761 Posted Topics

Member Avatar for paynegm

[code=python]def line_sum_and_count(line): """Finds the sum and count of the numbers in the given line of text.""" #----------------------------------------------------- data = line.split() tally = 0 for i in data: tally += float( i ) #------------------------------------------------------- return tally, len( data )[/code] Here's a different way to tackle the first function. I think your …

Member Avatar for jlm699
0
77
Member Avatar for usdblades
Member Avatar for usdblades
0
96
Member Avatar for jworld2

Here's a comparison: [code=python] >>> a = [1,2,3,4,5,6] >>> reduce(lambda y,x: x+y, a) 21 >>> sum = 0 >>> for i in a: ... sum+=i ... >>> sum 21 >>> [/code] Reduce is a way to perform a function cumulatively on every element of a list. It can perform any …

Member Avatar for jworld2
0
488
Member Avatar for predator78

sys.argv is used for passing command line arguments to your program. It is a list, and the first value [icode]sys.argv[0][/icode] is always the name of your program. So let's say you open up a terminal and type in [icode]python my_prog.py foo bar[/icode] Then sys.argv's contents would be [0] my_prog.py [1] …

Member Avatar for lllllIllIlllI
0
152
Member Avatar for mruane

Anybody who doesn't know what he's talking about and too lazy to google: [url=http://en.wikipedia.org/wiki/Roguelike]wiki[/url] If I were you I would look into pygame, as that would give you an easy-to-develop GUI with which to interact. The rest is simple python work.

Member Avatar for Freaky_Chris
0
208
Member Avatar for jworld2

PSST! Secret: [code=python] >>> import string >>> string.letters 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' >>> string.digits '0123456789' [/code] And PSST!!! To turn them into lists use list comprehension: [code=python] >>> [ lett for lett in string.letters ] ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', …

Member Avatar for jworld2
0
147
Member Avatar for jlm699

First you'll need to learn how to use code tags. As your code stands, it is unreadable because all indentation has been lost. If you use code tags, your code is not only readable, but forum members can easily copy and paste it into their code editors to tinker with. …

Member Avatar for vegaseat
0
119
Member Avatar for aot

This is strange. I'm getting [code=Traceback] Traceback (most recent call last): File "<input>", line 1, in <module> File "C:\Python25\lib\pickle.py", line 858, in load dispatch[key](self) File "C:\Python25\lib\pickle.py", line 1198, in load_setitem dict[key] = value TypeError: 'str' object does not support item assignment[/code] The object that you pickled, did it require any …

Member Avatar for woooee
0
982
Member Avatar for Tribesman

Don't double post... but regardless, check your other post in this same forum.

Member Avatar for jlm699
0
284
Member Avatar for keripix

also, which version of Python is this? If you are using the latest you should be using the subprocess module as it's much more efficient and easier to use than the old threading module, which is why it's becoming the new standard ;)

Member Avatar for woooee
0
96
Member Avatar for safir8100

You can look into paramiko for FTP use. I've used it before and it's VERY straight forward. The documentation provides plenty of examples of usage for connecting to an FTP server and retrieving files.

Member Avatar for jlm699
0
113
Member Avatar for bryanleo
Member Avatar for bryanleo

Please use code tags. They work like this: [noparse][code=<language>] My Code goes here! [/code][/noparse] Where <language> is any of the languages on DaniWeb (C, Perl, Python, HTML, PHP, etc.)

Member Avatar for bryanleo
0
232
Member Avatar for pythonprog

Here's how to ask for input: [url=http://docs.python.org/lib/built-in-funcs.html]Built-in functions[/url] Look down the page... there are two input methods. See if you can find them.

Member Avatar for jlm699
0
75
Member Avatar for paferlini

Kind of sounds like dependency issues... but seeing as that module is built into Python I don't see how this could happen. I tried importing those modules (which I've never used before) and they worked. Perhaps you need a reinstallation of Python.

Member Avatar for paferlini
0
606
Member Avatar for predator78

It's not exactly clear what this example is doing.. Plus this isn't a stand-alone example of the problem that you are seeing since we don't know what possible and matches are (ie, are they lists, tuples, dictionaries, strings?) ... If you could provide us with an idea of exactly what …

Member Avatar for predator78
0
117
Member Avatar for laspal

First of all, please use Code Tags. They make your post readable, and thus will make forum members more likely to read your problem and help you. Secondly, you say that only the last field is "changin", but that is the only variable that changes... [icode]for emailadd in mailing_list:[/icode]... see? …

Member Avatar for woooee
0
237
Member Avatar for bman923
Member Avatar for woooee
0
95
Member Avatar for niks1234

Here's one method to open and read a file: [code=python] f = open( 'myfile.txt', 'r' ) # 'r' is for Read Mode lines = f.readlines() f.close() # Now lines contains a list of each line of the file contents for eachline in lines: # Add line to wx.*ctrl [/code]

Member Avatar for niks1234
0
109
Member Avatar for ping24

I understand what you're trying to do but where is your question? Do you need to know what modules can be used for this or do you need help implementing a certain portion of this idea? etc...

Member Avatar for jlm699
0
160
Member Avatar for SoulMazer

[QUOTE=Ene Uran;691238]For the many of you who still want to know the solution, make variable 'a' a global:[/QUOTE] That or simply pass a to test: [code=python]words = ["aero", "aesthet", "andr", "arch", "arch", "ast", "baro",\ "biblio", "bio", "cardi", "chron", "cosm", "crat", "cycl", "dem", "dont",\ "dogma", "dox", "esth"] answers = ["air", "sense", …

Member Avatar for Dunganb
0
2K
Member Avatar for CelestialDog

You never imported your class... as I'm assuming that 'PathFinder' is not in your Main.py ... let's say it's in PF.py .... [icode]from PF import PathFinder[/icode] That should do it

Member Avatar for CelestialDog
0
232
Member Avatar for brainblitzkrieg

Google is your friend... learn how to use it: [url]http://www-128.ibm.com/developerworks/db2/library/tutorials/db2linux/db2proj/updated/python_db2_interface.htm[/url]

Member Avatar for jlm699
0
50
Member Avatar for lid

Yes. That would simply be a system call, which can be achieved by any number of Python methods (popen, os.system, subprocess, etc.). As far as the GUI portion that can also be achieved by any number of Python GUI toolkits (wxPython, Tkinter, EasyGUI, etc.) I refer you to [url=www.google.com]google[/url] for …

Member Avatar for jlm699
0
116
Member Avatar for vocalstud69

For the "GUI" portion of your program you'll likely want to look into wxPython. There are a number of other toolkits for creating GUIs but wx is by far the most native-looking so it'll get you a very clean looking interface that looks like it was built right into Windows. …

Member Avatar for zachabesh
0
3K
Member Avatar for TheNational22

Yes zachabest is correct. There is nothing special about a csv file. It is literally a text file that uses commas to delimit, or separate, each data cell of a row. Each new line is therefore a new row. I've found that using the csv modules are overkill and it …

Member Avatar for zachabesh
0
92
Member Avatar for mm013

Here's a snippet of a setup.py that I've used before to grab things that were not in the same directory... [code=python] setup( zipfile = None, # We use os.path.join for portability package_dir = {'': os.path.join('..', 'Common')}, py_modules = ['mylog', 'IPVerify', 'logfile', 'remoteCmd', 'rd_num_gen', 'crc32'], windows = [ { "script": "my_program.py", …

Member Avatar for mm013
0
320
Member Avatar for samjeba

Where does execution stop? Does it give an error? Where is this so-called "file open file print" statement?

Member Avatar for woooee
0
97
Member Avatar for zachabesh
Member Avatar for zachabesh
0
83
Member Avatar for fake-name

From the documentation [QUOTE]parse( source) Process an input source, producing SAX events. The source object can be a system identifier (a string identifying the input source - typically a file name or an URL), a file-like object, or an InputSource object. When parse() returns, the input is completely processed, and …

Member Avatar for jlm699
0
341
Member Avatar for massivefermion

Perhaps because you are appending to p1 instead of p ? although even after replacing p1 with p the list shows up empty... what exactly are you trying to do here? I have a feeling it's an indentation error...

Member Avatar for massivefermion
0
94
Member Avatar for LexiK

What have you tried so far? What errors are you running into? What are the rules of said game?

Member Avatar for jlm699
0
1,000
Member Avatar for hardik.38

I would suggest a nested for loop like: [code=python] for row in xrange( usr_row ): for col in xrange( usr_col ): ## Do my division and printing [/code]

Member Avatar for jlm699
0
97
Member Avatar for Dekudude

I have an inkling that he means reload a module... I too have looked around google and found some sites that insist that it can be done. I just don't know how. To further clarify when I'm developing a module and I import it into my python shell then realize …

Member Avatar for mathijs
0
3K
Member Avatar for pocnib

You're never reading your file... you're literally trying to read from sys.stdin. This is wrong and I think you may have misunderstood your prof. You need to open the file via [icode]open(file_name, mode)[/icode] ... then read from there....

Member Avatar for pocnib
0
165
Member Avatar for dineshdileep

...Adding on to the previous posts; another thing to keep in mind is that EVERYTHING in python is an object; meaning that the file handle (object) has methods and members that facilitate line-by-line iteration.

Member Avatar for zachabesh
0
91
Member Avatar for cglosser

HEre's a few things to get you on your way... first iterating over a list of files using the os module: [code=python] import os my_dir = '/home/AtomData/' ## path example for Windows: ## my_dir = 'C:\\XXX\\AtomData\' my_files = os.listdir(mydir) for each_file in my_files: ## Here we will do our file …

Member Avatar for jlm699
0
84
Member Avatar for damyt01

Paulthom also forgot to mention that the replace function has an optional third parameter that will help you greatly: [code=python] >>> t = 'I love cheese; cheese is my favorite thing to eat besides melted cheese.' >>> t.replace('cheese', 'Shredded Gorgonzola', 1) 'I love Shredded Gorgonzola; cheese is my favorite thing …

Member Avatar for jlm699
0
110
Member Avatar for tortoiseman

Yes, what vegaseat suggested... either that or use an escape (a la \) before the text as in: [code=python] >>> t = '!,.?'$%' >>> print t !,.?'$% >>> [/code] Same thing goes for double quotes within double-quoted string: [code=python] >>> t = "!,.?\"$%" >>> print t !,.?"$% >>> [/code]

Member Avatar for tortoiseman
0
83
Member Avatar for leegeorg07

This is similar to someone who wanted to use py2exe on linux ... both of these packages (py2app and py2exe) are somewhat misleading; as they do not simply build an executable 'version' of your program, they literally package your scripts together with an as-needed version of Python.

Member Avatar for Ene Uran
0
79
Member Avatar for mashimaro

One of the values that you are trying to concatenate is an integer. You need to wrap it with str() in order to convert it and concatenate. Also, I don't see you performing any commit() operations. If you do not commit your transactions they will never be posted to the …

Member Avatar for mashimaro
0
114
Member Avatar for besktrap
Member Avatar for 2ashwinkulkarni

To get a list of the contents of a folder you can use the os module's listdir() function. Then loop over each item, and use split('.') on the name to add '_output' before opening the output file.

Member Avatar for 2ashwinkulkarni
0
2K
Member Avatar for morraine

Your choice of words is very unique and I'm not sure that I understand your dilemma; but perhaps you are asking about passing parameters to a function that you've imported from another module? [code=python] import os os.listdir('/mydir/test/python') [/code] Like that.

Member Avatar for woooee
0
267
Member Avatar for dmpop
Member Avatar for Seagull One

Yes, it is defined within the same class but not in the scope of the function OnRecognition. say() is a member of the ContextEvents class so you'll need to call it as self.say()

Member Avatar for Seagull One
0
456
Member Avatar for dmpop

I think your best bet would be to simply print the value of contents and then ask the user for a new value. Otherwise you will need to figure out how to prompt for input and then subsequently write to the stdin ... you can access stdin/stdout via sys.stdxxx, which …

Member Avatar for dmpop
0
170
Member Avatar for iamoldest

I don't really know what you mean by your explanation of what's happening but I presume that you would want to modify your code to use if/else if structures as such: [CODE=python] while mainloop == 0: for event in pygame.event.get(): if event.type == KEYDOWN: draw_level() if event.key == K_ESCAPE: sys.exit() …

Member Avatar for jlm699
0
129
Member Avatar for Seagull One

Your current problem is probably that the location of easy_install is not on your windows path. For now, try typing in the full path to where you installed easy_install as such: [icode]C:\\Program Files\\<etc, etc>\\easy_install speech[/icode].

Member Avatar for Seagull One
0
1K
Member Avatar for leegeorg07

You're missing a parenthesis at the end of the [icode] v = float(raw_input([/icode] line. Also [icode]close = print "thank you for using a George Lee program"[/icode] is incorrect syntax. You can either print that string or save it using [icode]close =[/icode]. Which is it?

Member Avatar for leegeorg07
0
107

The End.