761 Posted Topics

Member Avatar for hughesadam_87

When you iterate over your file_list you could ignore the directories yourself like so: [code=python] file_list = glob.glob('*') for file in file_list: if not os.path.isdir(file): # Do my stuff now on only files[/code] EDIT: You could also just go through and strip out the directories with a list comprehension: [code=python] …

Member Avatar for vegaseat
0
154
Member Avatar for Mclovin

[QUOTE=Mclovin;899620]I want to create subfolders in already existing subfolders.[/QUOTE] Use [icode]os.makedirs()[/icode] to make directories. [QUOTE=Mclovin;899620]I'm just wondering about how to walk between folders.[/QUOTE] Use [icode]os.walk()[/icode] or [icode]os.chdir()[/icode] to move between directories.

Member Avatar for jlm699
0
3K
Member Avatar for gislik

Use class attributes. When you get the path from the user do something like this: [code=python] self.path = path [/code] Then your updateNebula method can be written like this: [code=python] def UpdateNebula(self, event=None): if 'path' in dir( self ) and self.path: print self.path[/code]

Member Avatar for vegaseat
0
135
Member Avatar for hughesadam_87

I agree with everyone else here. There should never ever be a reason to open this many files at once. Ever. You should explain what you're actually trying to do so that we can help you come up with an intelligent solution.

Member Avatar for jlm699
0
1K
Member Avatar for bryancan

[QUOTE=bryancan;899333]Is there a better way of doing this that I am just too new to know?[/QUOTE] Here's a suggestion: don't use csv reader. It's more overhead than you need for a csv file. Just read the line, strip off the white space (newline and trailing/leading spaces) and then split on …

Member Avatar for jlm699
0
149
Member Avatar for MONODA

And extending the above to a two element tuple: [code=python] >>> import random >>> random.seed() >>> mylist = [ ( random.randint(0, 100), random.randint(0, 100) ) for k in range(10) ] >>> print(mylist) [(83, 10), (74, 51), (19, 83), (14, 36), (12, 32), (91, 27), (96, 64), (20, 38), (37, 78), …

Member Avatar for MONODA
0
10K
Member Avatar for Jintu

To the both of you: In order to preserve indentation use code tags while posting code in this forum like so: [noparse][code=python] # Code goes inside here [/code][/noparse]

Member Avatar for vegaseat
0
232
Member Avatar for funfullson
Member Avatar for Stefano Mtangoo
0
88
Member Avatar for hughesadam_87

[QUOTE=shoemoodoshaloo;894053]The first thing I'd like to do is open a separate file for each name in the name list. For example, I'd like to have three files open, Jake.bed, Steve.bed, Adam.bed[/QUOTE] You could maintain a list of open file handles like this: [code=python] open_files = [] for each_name in names_list: …

Member Avatar for hughesadam_87
0
101
Member Avatar for jcmeyer
Member Avatar for hughesadam_87

[QUOTE=shoemoodoshaloo;893135][CODE]class FamilyDict(GeneDict): def __init__(self, file=None): GeneDict.__init__(self, file=None) self.Family_dict= {} infile = open(file) for key in dictionary.keys(): self.Family_dict.append(key)[/CODE][/QUOTE] It would help if you explained what was going wrong. Without that info all I can say is, where is the [ICODE]dictionary[/ICODE] coming from? You're iterating over its keys but I don't see …

Member Avatar for hughesadam_87
0
138
Member Avatar for drjay1627

[QUOTE=drjay1627;894014]AttributeError: Trie instance has no attribute '__len__'[/QUOTE] This indicates that the object you have passed to your recursive method is not a built-in datatype. I'm guessing it's a class that you wrote called Trie. In order to use the built-in [ICODE]len()[/ICODE] function on a user-defined object, you must overload the …

Member Avatar for jlm699
0
98
Member Avatar for galactica

Please use code tags when posting code in this forum. It makes your code readable and preserves indentation. [noparse][code=python] # Code goes in here [/code][/noparse] that aside, the keyerror you're getting is when you try to call an element in a dictionary that doesn't exist. Here's an illustration: [code=python] >>> …

Member Avatar for woooee
0
623
Member Avatar for Shraddha Kiran

1) Use code tags when posting code in this forum or most people will simply ignore your post. Use them like so: [noparse][code=python] # Code inside here [/code][/noparse] 2) What exactly is the problem? All you said is: [QUOTE]we have to feed in each url individually and sometimes modify it …

Member Avatar for Shraddha Kiran
0
155
Member Avatar for sciguy77

[QUOTE=sciguy77;891287]I tried both, neither worked. :([/QUOTE] If they're not working on the system where the server is running then your code is flawed. There was just a thread about this a few days ago that had a working server... Look there and try out that code.

Member Avatar for xav.vijay
0
447
Member Avatar for pupspark

[QUOTE=pupspark;891334]Actually, I'm new to programming all together. Thanks, though![/QUOTE] From where are you learning your python then? I'd like to destroy whatever the source may be...

Member Avatar for siddhant3s
0
206
Member Avatar for gujjar19

Like this, using string methods that can be applied on a line-by-line basis: [code=python] >>> '42'.isdigit() True >>> 'Test'.isdigit() False >>> [/code]

Member Avatar for jlm699
0
113
Member Avatar for pymatio

Why don't you put a check at the beginning of your script to see what your cwd is. Use os.getcwd() or os.listdir('.') to verify you're actually running your script from the proper directory.

Member Avatar for pymatio
0
121
Member Avatar for sciguy77

[QUOTE=sciguy77;887285]I put a print statement at the end to make sure that the whole script was executed. It was not.[/QUOTE] Did you put a print statement after [icode]serve_forever()[/icode]? I'm pretty sure that forever indicates a super loop (ie, [icode]while True:[/icode])

Member Avatar for sciguy77
0
162
Member Avatar for yamman13

Also keep in mind that idle may not be running in the same working directory as your script. Check that wish [icode]os.getcwd()[/icode]

Member Avatar for jlm699
0
68
Member Avatar for jimb90

I overdosed on caffeine once. Had to go to the hospital and drink charcoal and get a shot in the butt. Not cool.

Member Avatar for Tulsa
0
316
Member Avatar for infinitelygreen

[QUOTE=infinitelygreen;888353]So if I need EasyInstall to install EGG files, how do I install EasyInstall itself?[/QUOTE] I believe that the thought is 2.6 would be an upgrade only for the time being (since it's unlikely anybody would start using python26 before any other version). So you would use easyinstall from an …

Member Avatar for infinitelygreen
0
96
Member Avatar for leegeorg07

Don't use input as a variable name. Input is a python function that is equivalent to [icode]eval(raw_input(...))[/icode]... This may not solve your problem but it will help to distinguish whether this is a true problem or just semantics EDIT: Now I see it. you have to call lower(). Right now …

Member Avatar for leegeorg07
0
72
Member Avatar for tomtetlaw

You could use regular expressions... here's an example: [code=python] >>> import re >>> pattern = 'playername = (.*)' >>> rc = re.compile(pattern) >>> for line in ['playername = Johnny', 'playername = Foo Bar the Clown', 'somet hing other than playername', 'another dud', 'playername = Chocolate Rain']: ... rcm = rc.match(line) …

Member Avatar for jlm699
0
109
Member Avatar for EGG123

To take a series of lines in a text file that are separated by newline characters and mash them into a single line of text: [code=python] # Read from your input file using readlines(), then: out_txt = '%s %s' % (my_txt[0], ''.join(my_txt[1:])) [/code] Then you can write the out_txt to …

Member Avatar for woooee
0
105
Member Avatar for Stefano Mtangoo

You should listen to what the computer is telling you! [icode]Socket is not connected[/icode] implies that you forgot to connect your socket!! [code=python] sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect( (ipaddr, port) ) # ... etc [/code] EDIT: And keep in mind that connect() automatically binds the socket if it isn't already. …

Member Avatar for Stefano Mtangoo
0
290
Member Avatar for Summer_Intern
Member Avatar for Summer_Intern
0
2K
Member Avatar for vandenzergen

[QUOTE=thoughtcoder;886453]Traveling forward in time doesn't give any paradoxes.[/QUOTE] And if/when you return to your own time, do you sit idly by content knowing what will happen? If you stop acting your normal routine chaos theory suggests that an entirely different future would occur. So what then? What was the point …

Member Avatar for Salem
0
1K
Member Avatar for TeddyBear2155

Is there a speed mismatch? Any POST errors or entries in the System Event Log ? Does it just give a blank screen or does it *try* to boot but falls through all startup options?

Member Avatar for jlm699
0
87
Member Avatar for SoulMazer

[code=python] loadWords() [/code] This is your problem. While the function actually returns the dictionary, you're never actually "catching" with anything. You should be doing something like this: [code=python] my_results = loadWords() [/code] Then the variable [ICODE]my_results[/ICODE] will contain whatever object is passed back from the function [ICODE]loadWords()[/ICODE]

Member Avatar for jlm699
0
104
Member Avatar for njparton

[QUOTE=njparton;887216]I also use the left() and right() functions in vba to remove any whitespaces and text characters from the resulting string, any ideas on how to do that in python most gratefully received! [/QUOTE] Use [icode]strip()[/icode] like so: [code=python] >>> padded = ' foobar ' >>> padded1 = 'foo ' …

Member Avatar for njparton
0
202
Member Avatar for zoro007

[code=python] import os os.system( 'cat file.txt | grep "line2="' ) [/code] Sometimes the simplest solution is the best one.

Member Avatar for siddhant3s
0
126
Member Avatar for sravan953

Here's one way: [code=python] open_file=open('html.html','r') file_lines=open_file.readlines() file = file_lines[0].strip() # First Line loc_file = file_lines[1].strip() # Second Line [/code] HTH NOTE: Using file for a variable name is not recommended as it's a reserved word in Python... I'd use something else... maybe something that's descriptive.

Member Avatar for vegaseat
0
8K
Member Avatar for Aestter

In the future, please use code tags when posting code in this forum, it makes your code actually readable instead of a wall of unformatted, garbled text. Use code tags like this: [noparse][code=python] # Code inside here [/code][/noparse]

Member Avatar for sravan953
0
171
Member Avatar for gujjar19

Here's a possible way to get you started (note this is untested): [code=python] inp = """<FONT COLOR="ff99ff"> So hold onto your special friend </font> - Wheels, one eight, wheels. <SYNC Start=2474996><P Class=ENCC> <FONT COLOR="ff99ff"> You'll need something to keep her in <SYNC Start=2480275><P Class=ENCC> <FONT COLOR="ff99ff"> now you stay inside …

Member Avatar for gujjar19
0
143
Member Avatar for gujjar19
Member Avatar for gujjar19
0
83
Member Avatar for drjay1627
Re: Trie

[QUOTE=drjay1627;883578]I'm trying to code a Trie in Python. Any suggestions as to where I should begin? drjay[/QUOTE] I suggest searching the internet using this crazy tool called the Googles. Here was my first hit: [URL="http://en.wikipedia.org/wiki/Trie"]http://en.wikipedia.org/wiki/Trie[/URL]

Member Avatar for jlm699
0
112
Member Avatar for brashli

To convert from a string to int or float cast it using [icode]int()[/icode] or [icode]float()[/icode] like so: [code=python] >>> s = '7500' >>> int(s) 7500 >>> int(s) / 10 750 >>> float(s) / 5 1500.0 >>> [/code]

Member Avatar for jlm699
0
153
Member Avatar for hughesadam_87

[QUOTE=shoemoodoshaloo;883635]Also, am I confusing the terminology of instance and method here?[/QUOTE] Yes. A method is a function. So a class's method would be one of the functions you have defined in your class. The instance is what you do to actually create and object of that class. So [code=python] class …

Member Avatar for jlm699
0
179
Member Avatar for jaseerabubakar
Member Avatar for jlm699
0
209
Member Avatar for ia2196

Please use code tags. You will get more answers to your question if your post is friendlier to read. To do this, you simply place tags around your code like so: [noparse][code=python] # This is where your code goes # In here between the code tags [/code][/noparse] Doing this will …

Member Avatar for jlm699
0
82
Member Avatar for SoulMazer

EDIT: Re-read the question, realized what you're asking.... [code=python] qs = { "cerebellum":"The brain region which controls the coordinates muscular activity\na. medulla oblongata\nb. cerebrum\nc. cerebellum\nd. optic lobe\ne. brain stem", #.... etc } # key, value = qs['cerebellum'] print(value) usr_inp = raw_input('Your answer: ') if usr_inp == key[0]: print 'Correct!' [/code] …

Member Avatar for SoulMazer
0
135
Member Avatar for mahela007

[icode]os.popen[/icode] allows you to execute a system call from within Python, as if you were in the command line. Note that this method would only work on Windows platforms...

Member Avatar for mahela007
0
12K
Member Avatar for hughesadam_87

You need to instantiate the class by creating an instance of it. So if your class is called [icode]FormatData[/icode] as in your example above, you would create an object like so: [CODE=python] # Assuming the class FormatData has # already been defined or imported from # another module... def main(): …

Member Avatar for vegaseat
0
414
Member Avatar for SoulMazer

First of all, what version of Python are you using? If it's anything earlier than 3.0 do not use [icode]input()[/icode], rather [icode]raw_input()[/icode] (in the same manner). It already forces the user input to string and doesn't allow for malicious things to happen. Now, the problem in this case is likely …

Member Avatar for SoulMazer
0
154
Member Avatar for jephthah

[QUOTE=jephthah;868971]just merely in a general sense, why wouldn't life on an "earth-like" planet naturally evolve into creatures more or less "similar to" the life forms that have evolved here?[/QUOTE] I guess the real question is: why would it? Evolution is a very slow process, and even still multiple organisms can …

Member Avatar for jephthah
1
149
Member Avatar for chri5ty

[QUOTE=chri5ty;871906]I hate that I had to search and search and search to find complete information about the differences between Intel CPUs. But even when I thought I found the right information, someone told me I was still wrong to some aspects. There is either a serious lack of documentation about …

Member Avatar for Jupiter 2
0
247
Member Avatar for Aestter

How about your actual game code? Can't really debug what the problem is without it... My gut feeling is that you don't need to specify pygame.mixer.module; try searching this forum for vegaseat's excellent and simple py2exe script that should pull in your basic modules.

Member Avatar for Aestter
0
595
Member Avatar for mg0959

You can debug this yourself. Try pinging that ip address and port. Helps to find root cause first

Member Avatar for mg0959
0
153
Member Avatar for perksieuk

[QUOTE=perksieuk;876685] [code=python]destination = r'[...]\test_merge\25514.txt' open_destination_write = open(destination, 'w') open_destination_append = open(destination, 'a') [/code] [/QUOTE] I can't fully answer your question without an example of input and expected output; however here's my two observations. First, you are opening the [ICODE]test_merge\25514.txt[/ICODE] file twice, under two separate file handles. First in 'write' mode, …

Member Avatar for Deepak.G
0
97

The End.