761 Posted Topics

Member Avatar for Nanz

[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 …

Member Avatar for jlm699
0
63K
Member Avatar for vmars
Member Avatar for adam291086

[url=http://www.amk.ca/python/howto/regex/regex.html]Here's[/url] some good reading on regular expressions.

Member Avatar for Gribouillis
0
104
Member Avatar for jmn0729

[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]

Member Avatar for Gribouillis
0
411
Member Avatar for oldSoftDev

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 …

Member Avatar for oldSoftDev
0
108
Member Avatar for tomtetlaw

[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]

Member Avatar for tomtetlaw
0
199
Member Avatar for MaxVK

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...

Member Avatar for MaxVK
0
1K
Member Avatar for punmeister

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 …

Member Avatar for punmeister
0
122
Member Avatar for Darkangelchick

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 …

Member Avatar for Darkangelchick
0
215
Member Avatar for powrhouse1

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 …

Member Avatar for powrhouse1
0
96
Member Avatar for adam291086
Member Avatar for adam291086
0
99
Member Avatar for Stefano Mtangoo

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.

Member Avatar for Stefano Mtangoo
0
72
Member Avatar for Stefano Mtangoo

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.

Member Avatar for Stefano Mtangoo
0
205
Member Avatar for Devlan

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 …

Member Avatar for vegaseat
0
124
Member Avatar for Feenix45

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]

Member Avatar for Feenix45
0
159
Member Avatar for DATA777

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 = …

Member Avatar for jlm699
0
109
Member Avatar for jcafaro10

[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) …

Member Avatar for jlm699
0
115
Member Avatar for Devlan

[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

Member Avatar for Devlan
0
101
Member Avatar for Stefano Mtangoo

Was this supposed to be a question or just you telling us what your next project is?

Member Avatar for Stefano Mtangoo
0
424
Member Avatar for sma.arch
Member Avatar for jlm699
0
142
Member Avatar for wirth.jason

[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, …

Member Avatar for jlm699
0
1K
Member Avatar for ccandillo

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 …

Member Avatar for ccandillo
0
145
Member Avatar for Lum1n0us

For completeness' sake and the benefit of future posters, could you post the code here that solved your problem?

Member Avatar for jlm699
0
656
Member Avatar for ashain.boy

[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.

Member Avatar for bvdet
0
91
Member Avatar for heyitsme

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 …

Member Avatar for woooee
0
92
Member Avatar for superman71903

If you read the information on the website provided you will see that pyro will do exactly what you're looking for.

Member Avatar for superman71903
0
127
Member Avatar for MaxVK

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]

Member Avatar for MaxVK
0
81
Member Avatar for ccandillo

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 …

Member Avatar for ccandillo
0
174
Member Avatar for gab_sk

Can you provide some code to demonstrate the problem? It will be much easier to understand the problem

Member Avatar for jlm699
0
140
Member Avatar for bvrclvr1

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 …

Member Avatar for lllllIllIlllI
0
192
Member Avatar for gotrobotfriends

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.

Member Avatar for gotrobotfriends
0
99
Member Avatar for adam291086

[QUOTE]0 --> Adam[/QUOTE] I don't see any errors? Your query syntax looks correct so what's the problem exactly?

Member Avatar for Stefano Mtangoo
0
118
Member Avatar for grambo

[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 …

Member Avatar for jlm699
0
129
Member Avatar for Cali45

Which part are you struggling with? Here's how you open a file: [code=python] fh = open( 'file.txt' ) [/code]

Member Avatar for jlm699
0
96
Member Avatar for MaxVK

Yes, RichTextCtrl is usable, I believe vegaseat has an example or two in the wx sticky thread on this forum.

Member Avatar for MaxVK
0
390
Member Avatar for OutOfReach

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

Member Avatar for Ene Uran
0
208
Member Avatar for chebude

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 …

Member Avatar for jlm699
0
110
Member Avatar for Bouzy210

[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 …

Member Avatar for jlm699
0
152
Member Avatar for chg

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]

Member Avatar for crono5788
0
150
Member Avatar for ihatehippies

This is most likely Vista related. Are you running this wx code stand-alone or using IDLE to launch it?

Member Avatar for Stefano Mtangoo
0
154
Member Avatar for Stefano Mtangoo

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 …

Member Avatar for Stefano Mtangoo
0
80
Member Avatar for samkasarla_nz

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]

Member Avatar for jlm699
0
91
Member Avatar for sourceofthought

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 …

Member Avatar for sourceofthought
0
122
Member Avatar for ihatehippies

I think you may need to use [icode]demo.a_listbox.insert(0,"whatever")[/icode], since demo is the instance of Testgui.

Member Avatar for ihatehippies
0
110
Member Avatar for drjekil

[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 > "

Member Avatar for drjekil
0
159
Member Avatar for kaisoze
Member Avatar for paferlini

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 …

Member Avatar for jlm699
0
94
Member Avatar for Weebl4551

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 …

Member Avatar for jlm699
0
186
Member Avatar for kempablavitt

[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.

Member Avatar for lllllIllIlllI
0
180
Member Avatar for kbjr14
Member Avatar for jlm699
0
115

The End.