761 Posted Topics
Re: 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] … | |
Re: [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. | |
Re: 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] | |
Re: 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. | |
Re: [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 … | |
Re: 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), … | |
Re: 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] | |
Re: [URL="http://lmgtfy.com/?q=mysql+python3&l=1"]STFW[/URL] | |
Re: [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: … | |
Re: Which is located on the ftp site, the file or the application? | |
Re: [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 … | |
Re: [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 … | |
Re: 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] >>> … | |
Re: 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 … | |
Re: [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. | |
Re: [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... | |
Re: Like this, using string methods that can be applied on a line-by-line basis: [code=python] >>> '42'.isdigit() True >>> 'Test'.isdigit() False >>> [/code] | |
Re: 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. | |
Re: [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]) | |
Re: 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] | |
Re: I overdosed on caffeine once. Had to go to the hospital and drink charcoal and get a shot in the butt. Not cool. | |
Re: [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 … | |
![]() | Re: 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 … ![]() |
Re: 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) … | |
Re: 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 … | |
Re: 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. … | |
Re: How about a little context? It would help us to see some code so we know what you're working with | |
Re: [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 … | |
Re: 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? | |
Re: [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] | |
Re: [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 ' … | |
Re: [code=python] import os os.system( 'cat file.txt | grep "line2="' ) [/code] Sometimes the simplest solution is the best one. | |
![]() | Re: 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. |
Re: 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] ![]() | |
Re: 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 … | |
Re: You need to add a [icode]'\n'[/icode] new line character to each line. | |
Re: [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] | |
Re: 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] | |
Re: [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 … | |
Re: Google appears to be blocking the method you're using. Have you tried any debugging? | |
Re: 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 … | |
Re: 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] … | |
Re: [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... | |
Re: 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(): … | |
Re: 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 … | |
Re: [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 … | |
Re: [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 … | |
Re: 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. | |
Re: You can debug this yourself. Try pinging that ip address and port. Helps to find root cause first | |
Re: [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, … |
The End.