761 Posted Topics
Re: [QUOTE=Nanz;749440]hoe to write a generic code for creating a empty 2D array and dynamically insert values in it.[/QUOTE] [code=python] >>> arr_2d = [[]] >>> arr_2d[0].append(0) >>> arr_2d[0].append(1) >>> arr_2d.append([3,4,5]) >>> arr_2d [[0, 1], [3, 4, 5]] >>> [/code] It might benefit you to create a 2d array class to handle … | |
Re: [QUOTE=evstevemd;710123]if It was avote, I'll give mine to wxpy![/QUOTE] +1 | |
Re: [url=http://www.amk.ca/python/howto/regex/regex.html]Here's[/url] some good reading on regular expressions. | |
Re: [QUOTE=jmn0729;720878]* I understand that the spaceing is off, but it is because of the quote box[/QUOTE] Instead of quote use code tags: [noparse][code=python] The code goes in here and doesn't lose formatting [/code][/noparse] | |
Re: Please wrap your code in tags when posting it to this forum, so that it won't lose indentation, thereby allowing us to easily read your code: [noparse][code=python] #Python code in here [/code][/noparse] When reading from a file it is good practice to use [icode]strip()[/icode] on every line to remove the … | |
Re: [QUOTE=Murtan;748104]Your loop starting on line 129 is only one line long (130)[/QUOTE] AKA, infinite loop: [code=python] while 1: clock.tick(60) [/code] | |
Re: I don't quite remember but I believe that treectrl structure can be loaded from a dictionary, right? If that is correct then you can simply use pickle to store/load the dictionary.. which will save a few lines of code I guess... | |
Re: You're calling the function findprogram before defining it.... if you simply rearrange your code so that the [icode]def findprogram(program):[/icode] block is first, you'll solve the problem. You'll then find that you forgot to [icode]import sys[/icode] And then you'll find that you're trying to use some variable called program_path when instead … | |
Re: Please use code tags when posting blocks of code, and icode tags when posting small snippets. This will make sure your formatting is not lost to the ether; and will also make your posts easier for us to read; thereby making it easier for us to help you. You can … | |
Re: There's many ways to do this, here's two examples: [code=python] >>> stack = 'test.tif' >>> new_name = stack.split('.')[0] + '.png' >>> new_name 'test.png' [/code] Simply split at the '.' and use the first part of the name, then add on .png This is very straight forward, however it may produce … | |
Re: Look into [url=http://freshmeat.net/projects/soappy/]SOAPpy[/url]. | |
Re: Your problem is that you've got prod_cost as both a function and a variable. So once your assigning a value to prod_cost, it removed the definition of prod_cost as a function. | |
Re: I believe [url=http://www.python.org/doc/2.5.2/lib/module-ctypes.html]ctypes[/url] is a way for Python to load dll files. | |
Re: pickling is more beneficial for custom classes. For a built-in class (dictionary, list, etc.) simply use eval (NOTE: this solution has been posted before on this forum, but I couldn't find it) [code=python] >>> d1 = {'a':2, 'b':3} >>> d2 = eval(repr(d1)) >>> d2 {'a': 2, 'b': 3} >>> d2['c']=1 … | |
Re: Here's an example of reading the file into a dictionary: [CODE=python] def load_IDs(): infile=open("tab.txt","r") lines=infile.readlines() infile.close() my_IDs = {} for line in lines: data=line.strip().split(",") my_IDs[ data[ 0 ] ] = data[ 1 ] return my_IDs [/CODE] | |
Re: Are you asking about passing keyword/argument lists to functions/classes? Here's a very basic example to illustrate, let me know if this is what you're asking: [code=python] >>> class VarKeyArg(object): ... def __init__(self, *args, **kwargs): ... self.key1 = kwargs.get('key1') ... self.key2 = kwargs.get('key2') ... self.extra = args[:] ... >>> c1 = … | |
Re: [QUOTE=jcafaro10;737900] I think it's because I'm redeclaring the class everytime.[/QUOTE] Right.. so try something like this: [code] # My class class ballCollisionListener(animation.CollisionListener): def collisionDetected(self,event): print "Python Collision: ",ball,ball.getX(),ball.getY() if event.getSource()==boundary: if ball.getX()<=0 or ball.getX()+ball.getWidth()>=boundary.getWidth(): ball.setXSpeed(-ball.getXSpeed()) elif ball.getY()<=0 or ball.getY()+ball.getHeight()>=boundary.getHeight(): ball.setYSpeed(-ball.getYSpeed()) elif event.getSource()==paddle: ball.setYSpeed(-ball.getYSpeed()) for i in range(1,3): ball = animation.AutoMoveItem(images.get("Ball"),(200+40*i),50,20,20,-5,5) … | |
Re: [QUOTE=Devlan;719704] [CODE=python] print p.Hi #This prints the location... [/CODE] get <__main__.add instance at 0x00A98FD0> Um... why?[/QUOTE] Because you asked for it ;) [code=python] print p.Hi() #This prints the location... [/CODE] HTH | |
Re: Was this supposed to be a question or just you telling us what your next project is? | |
Re: Maybe try adding a delimiter character that you can use to split the messages. | |
Re: [code=python]>>> class mydict(dict): ... def __init__(self, arg): ... self['a'] = arg ... self['b'] = self.get_b() ... ... def get_b(self): ... return self['a'] ... >>> d3 = mydict(6) >>> d3['b'] 6[/code] Here's the help for property: [QUOTE] >>> help(property) Help on class property in module __builtin__: class property(object) | property(fget=None, fset=None, … | |
Re: You want to create a hyperlink [i]within[/i] the terminal window? I don't know if that would be possible through standard means, and using curses would be overkill in my opinion. Does this script require to be used within the terminal or would you be willing to give it a nice … | |
Re: For completeness' sake and the benefit of future posters, could you post the code here that solved your problem? | |
Re: [QUOTE=ashain.boy;734745]separated by \t and \n[/QUOTE] If the entries are split by tabs then you can use [icode]line.split('\t')[/icode] on each line to separate those values. If they're only split by one space then it'll take some concerted effort to identify the numbers and then read backwards to get the city name. | |
Re: Let me start you off with opening and reading a csv file: [code=python] fh = open( 'test.csv', 'r' ) lines = fh.readlines() fh.close() for each_line in lines: line_data = each_line.strip().split(',') [/code] The [icode]open()[/icode] method allows you to open a file, which I opened in the 'r' mode (for reading). I … | |
Re: If you read the information on the website provided you will see that pyro will do exactly what you're looking for. | |
Re: I think the better way would just be to map CTRL+<character> to the items under an Edit menu. ie, [code] File, Edit, Help |_Bold Ctrl+B |_Italic Ctrl+I [/code] | |
Re: I ran the code unmodified and got this: [QUOTE=output]Nov 12 - /tor/cto/915709511.html FS: 2004 Honda Civic Si Low Km - $12500 - Nov 12 - /tor/cto/915669421.html FS; 1993 HONDA CIVIC CX HATCHBACK (EG) - $850 - Nov 12 - /tor/cto/915654012.html FS: 1997 HONDA CIVIC CX HATCHBACK - $1500 - Nov … | |
Re: Can you provide some code to demonstrate the problem? It will be much easier to understand the problem | |
Re: Let's do this one step at a time. The text file is kind of ugly, but here's a quick example of extracting info. [code=python] >>> f = open('Schedule.txt') >>> r = f.readlines() >>> f.close() >>> >>> data_found = 0 >>> for each_line in r: ... if not data_found: ... if … | |
Re: Pretty sure that #p189191 is not a valid web address. Also, use [noparse][url=http://www.google.com]Click here for Google[/url][/noparse] for hyperlinks in this forum. | |
Re: [QUOTE]0 --> Adam[/QUOTE] I don't see any errors? Your query syntax looks correct so what's the problem exactly? | |
Re: [QUOTE=grambo;732264] [code=python] for featureline in ffeaturefile.readlines(): featureline = featureline.strip().split("|") addlist += "'%s', '%s'," % (featureline[0], featureline[3]) resfeaturelist = dict(addlist) [/code] [code=python] for number, resline in enumerate(fresfile): resline = resline.strip().split("|") for count in [0, 21]: if (count == 21): #change values to text in features.txt resfields = resline[count].split(",") for i, item … | |
Re: Which part are you struggling with? Here's how you open a file: [code=python] fh = open( 'file.txt' ) [/code] | |
Re: Yes, RichTextCtrl is usable, I believe vegaseat has an example or two in the wx sticky thread on this forum. | |
Re: There is an ordered dictionary module that can be found [url=http://www.voidspace.org.uk/python/odict.html]here[/url]. Works just like a regular dictionary but is kept in order. HTH | |
Re: To avoid this problem in the future you could do this: [code=python] def read_rebase(filename): enz_dict={} infh= open("rebase.dat") for line in infh.xreadlines(): fields = line.split() if len(fields) > 2: name = line.split()[0] pat = line.split()[2] enz_dict[name] = get_site_only(pat) infh.close() return enz_dict [/code] This way you make sure that the number of … | |
Re: [QUOTE=Bouzy210;730897]what I am doing wrong. [CODE] docs = open(file, 'r') lines = docs.readlines() for lines in docs: if lines.startswith('%s' % get) and endswith("%s" % tags['%s' % get]): print line else: pass docs.close() [/CODE][/QUOTE] You read in contents of docs to lines, but then try to iterate over docs using the … | |
Re: Alternately if you knew there would always be a space after the number: [code=python] s = '105 mV' number = s.split(' ')[0] print number[/code] | |
Re: This is most likely Vista related. Are you running this wx code stand-alone or using IDLE to launch it? | |
Re: MySQL and PostgreSQL are a [url=http://www.databasejournal.com/features/mysql/article.php/3288951]matter of taste[/url]. For me, PostgreSQL just happened to be easier to pick up and the Python module to interface with postgres DB was cleaner and better documented... I don't know what the state of either module is these days however. I doubt that MySQLdb … | |
Re: Here's an example: [code=python] import os my_path = 'C:\\sam' if os.path.isdir( my_path ): print 'C:\\sam is a valid path' else: os.makedirs( my_path ) if not os.path.isdir( my_path ): print 'Path creation failed' [/code] | |
Re: Let's try to translate a few key commands into Python... Set srvr=%1 srvr = sys.argv[1] sys.argv contains the list of input parameters. Index 0 ( [0] ) always contains the name of the program. Don't forget you'll need to [icode]import sys[/icode] to access this item. pause time.sleep(1) time.sleep(1) tells execution … | |
Re: I think you may need to use [icode]demo.a_listbox.insert(0,"whatever")[/icode], since demo is the instance of Testgui. | |
Re: [code=python] >>> import random >>> my_seq = ''.join([random.choice('AGTC') for x in range(10)]) >>> my_seq 'TATCCTTGTT' >>> len(my_seq) 10 >>> [/code] I'm not quite sure what you mean by "printing in FASTA format with the > " | |
![]() | |
Re: Which part do you have problems with? the web form or the PYthon processing? For a web form I suggest using a simple [url=http://googledocs.blogspot.com/2008/02/stop-sharing-spreadsheets-start.html]Google Docs form[/url], that you can embed on any website. Any data entered into the form will then be populated into a spreadsheet of your choosing. The … | |
Re: If you wrap your code in code tags and explain to us your error we will gladly help. Please put your code between tags like this: [noparse][code=python] # Your code in here [/code][/noparse] This way your code won't look like a garbled mess with no indentation. Also, please explain to … | |
Re: [QUOTE=kempablavitt;727639]I need help to get started with this. Any one that knows any examples I can get inspire from? :) [/QUOTE] Looks like he's starting from scratch. | |
Re: [url=http://oakroadsystems.com/math/polysol.htm] Here you go[/url] |
The End.