ghostdog74 57 Junior Poster

I assume you are working on win32 platform
if you have the win32 module, there is an example demo called win32netdemo.py and inside the source, there is a function call ServerEnum(). You can take a look at how to find network shares.
Another way is to call a system command that is able to find the network shares and put them into a file. Then from Python, open the file for processing..

ghostdog74 57 Junior Poster

Ok thanx, this has helped me understand the problem and partially solve it, however, there is an additional problem.

When i concatate several unicoded characters like this:

a = unichr(88).encode('utf8')
b = unichr(257).encode('utf8')
c = unichr(109).encode('utf8')
d = unichr(258).encode('utf8')
print a,b,c,d
e = a+b+c+d
print e
for i in e:
    print i

How can i retrieve the original integers (88,257,109,258) from string e?
Since all characters above 255 contain two characters, how can i than determine which characters belong together, so i can decode them together (using ord()).

In other words, can i split the string in a certain way, so that it contains 'whole' characters.
I know that flash actionscript can to this, this advanced language must be able to do the same.

....
dec = e.decode('string_escape').decode('utf8')
for i in dec: print ord(i),
...
ghostdog74 57 Junior Poster

you could try this:

>>> a = unichr(275).encode('utf8')
>>> b = a.decode('utf8')
>>> b
u'\u0113'
>>> ord(b)
275
ghostdog74 57 Junior Poster

That example would not allow for wildcards, a talent of module glob only. However, you can simply leave out the if statement in the list comprehension line:

filelist = [ os.path.join(root,fi) for fi in files ]

thanks..yes i know.
I was giving an example on his first post.. doc and txt files. :)

ghostdog74 57 Junior Poster

Is there a way though, to make it also scan sub directories?

Just an example only:

import os
allfiles = [] #store all files found
for root,dir,files in os.walk("C:/Documents and Settings/Matt/Desktop"):	
 	filelist = [ os.path.join(root,fi) for fi in files if fi.endswith(".doc") or fi.endswith(".txt") ]
 	for f in filelist: 
              allfiles.append(f)
	
	
for i in allfiles:
	print "file ", i
ghostdog74 57 Junior Poster
def prompt_rea():
    global gold
    ....
    ....

Can you see the problem?

if you want to use gold as global, u might like to put "global gold" inside prompt_rea()

ghostdog74 57 Junior Poster

Here is the current code. Thanks for your help. I've tried comparing each individual index after sorting both lists, so 1=1 2 != 2 3=3 etc
but there is a error: object "list" cannot be called:

....
    if user_list(index) == comp_list(index):
  ....

change the () to [] , it should be

if user_list[index] == comp_list[index]:
ghostdog74 57 Junior Poster

Thanks, but now I'm stuck on the next step, to allow the user to input their own numbers and compare them:

import random
r=[]

def randomness():
    print "show 6 random unique integers from 1 to 50: "
    sample1=random.sample(range(0,50),6)
    print sample1
    i=0
    while i != 6:  
        for k in range(6):
            r = input('Type a random unique number from 1 - 50: ')
            i=i+1
def startup():
    n=0
    randomness()
    while n !=6:
        if r == sample1:
            print "Exact Match!"
        else:
            print 'Try again'
            n=n+1
    
startup()
if n == 6:
    print "no matches"
else:
    print "congrats, it's a match"

This part is hard, although I think I have got the wrong idea.

you did not return values from randomness() , so in startup(), you can't use sample1.
anyway, what is it that you are trying to do?
do you need the user to guess all 6 random numbers?

ghostdog74 57 Junior Poster

Unique random variables. I've tried modifying the code in varying ways, but nothing is working. The program won't add new numbers to replace the ones that were duplicates.

import random
b=0
numbers=[]
print "show 6 random unique integers from 1 to 50: "
while b < 6:
    for k in range(6):
        k = random.randint(1,10)
        numbers.append(k)
        b=b+1
    setA = set(numbers)
    numbers = list(setA)
print numbers

It's getting silly now.

how about using random.sample()?
eg

>>> import random
>>> random.sample(range(0,50),6)
[19, 39, 44, 13, 8, 31]
ghostdog74 57 Junior Poster

If anyone figures out a different way to sort by word length....

>>> list1 = ['Herring','used','to','be','abundant','in','the','Atlantic','Ocean','then','herring','got','overfished']
>>> lengthlist = map(len,list1)
>>> lengthlist
[7, 4, 2, 2, 8, 2, 3, 8, 5, 4, 7, 3, 10]
>>> all = zip(lengthlist,list1)
>>> all
[(7, 'Herring'), (4, 'used'), (2, 'to'), (2, 'be'), (8, 'abundant'), (2, 'in'), (3, 'the'), (8, 'Atlantic'), (5, 'Ocean'), (4, 'then'), (7, 'herring'), (3, 'got'), (10, 'overfished')]
>>> allzip.sort()
>>> for i in allzip:
... 	print i
... 
(2, 'be')
(2, 'in')
(2, 'to')
(3, 'got')
(3, 'the')
(4, 'then')
(4, 'used')
(5, 'Ocean')
(7, 'Herring')
(7, 'herring')
(8, 'Atlantic')
(8, 'abundant')
(10, 'overfished')

don't know whether its what you mean by sort by word length..pardon me if not..

ghostdog74 57 Junior Poster

# sum.py
# tpm
# A program that accepts an indeterminate (any number) of integers entered by
# the user, calculates and their sum, using loop

from math import *

def calc_sum():
    n = input("Enter any number: ")
    sum = 0.0
    for i in range(n):
        x = input("Enter a number >> ")
        sum = sum + x
    print "\nThe sum of the numbers is", sum / n

main()

:sad: :mad: :confused: :o :( :cry: :evil:

why do you need to /n when you only want to calc the sum of these numbers?
and where is your main() ?? it should be calc_sum() right?

ghostdog74 57 Junior Poster

Hello to all,

I am trying to create a script that will go through certain directorys in Windows and pull out the files I stated by extentions. Which will then later copy to a location either on the local machine or an external HD.

Any assistence will be greatly appricated.
Thanx in advance,

ParE

what have you tried so far?

anyway, you can look up the manuals of some of these tools
- os.walk
- glob
- shutil
- os.path.splitext

to achieve what you need

ghostdog74 57 Junior Poster

I am fairly familiar with C, but new to Python. Does Python have something like the handy C conditional expression? For example:

// C conditional expression  x = a ? b : c;
// if a is true then x = b else x = c
// here used to print 10 numbers in each row
// the numbers are separated by tabs, each row ends with a '\n'

#include <stdio.h>

int main()
{
  int k;

  for(k = 0; k < 100; k++)
  {
    printf("%3d%c", k, (k % 10 == 9) ? '\n' : '\t');
  }
  
  getchar();  // make the console wait
  return 0;
}

in version 2.5, there will be implementations of conditional.
Look here