761 Posted Topics

Member Avatar for Joe Hart

You need to pass a second parameter to the open function which will declare the mode that you're opening the file in. Default (no parameter as in your case) is read mode or 'r'. You want either write or append depending on if you want to wipe the file clean …

Member Avatar for baki100
0
144
Member Avatar for girishmsampath
Member Avatar for Dlsqueak

When you open your file you should be opening it in append mode using the 'a' flag (right now you're opening it in write mode, 'w').

Member Avatar for Dlsqueak
0
81
Member Avatar for qadsia

This is a very hacked solution but: [code=python] >>> sports = ## Defined as above - snipped for length >>> def build_html(chosenCategory): ... up_locals = sys._getframe(1).f_locals ... for each_var in up_locals: ... if id(up_locals[each_var]) == id(chosenCategory): ... var_name = each_var ... filename = '%s.html' % (var_name) ... print filename ... …

Member Avatar for qadsia
0
266
Member Avatar for zyrus001

[QUOTE=zyrus001;1000490]Hi! I have a list of class objects, each object contrains a dictionary. Is it possible to sort my list based on a value within each object's dictionary? Can I use the list.sort() method to do this? Thx![/QUOTE] Yes. You'll need to use the function parameter of the sort method. …

Member Avatar for jice
0
244
Member Avatar for persianprez

In order to read the contents of [icode]code.txt[/icode], you'll need to read the [URL="http://docs.python.org/library/sys.html#sys.stdin"]stdin pipe[/URL]. To access it, use the [icode]sys.stdin[/icode] handle, which you can read from just like an open file handle. You'll need to use the sys module, obviously. The rest is just coding the cypher. HTH

Member Avatar for ov3rcl0ck
-1
291
Member Avatar for shakilaf

Does your laptop also have an open mail server listening on the default port? smptlib provides methods to connect to an smtp mail server, but if your laptop is not currently running one, then you cannot send mail to it.

Member Avatar for Dan08
0
2K
Member Avatar for Mensa180

Mensa: your code was very well structured and a nice example of reading user input then using it for calculation. Here's how I've modified your code: [code=python] def calc_payment(int_rate, num_pmnts, principal, freq): ''' This function will calculate the payment amount of a loan. @ Inputs - int_rate - The interest …

Member Avatar for Mensa180
1
342
Member Avatar for sravan953

[QUOTE=sravan953;1009872][code=python] self.marks.append(self.twelve.GetValue()) self.average=sum(self.marks)/len(self.marks)[/code][/QUOTE] Note that [icode]GetValue[/icode] returns a string. In order to use [icode]sum[/icode] you'll need to convert all elements of [icode]self.marks[/icode] to integers or floating points. You could probably get away with using a [icode]try[/icode]/[icode]except[/icode] block like this: [code=python] >>> marks = ['1','2.5','3','4.2','5','6.6666','7.111'] >>> new_marks = [] >>> for …

Member Avatar for snippsat
0
683
Member Avatar for pmennen

I saw it mentioned somewhere on the web that you need to import [icode]PyQT4[/icode] instead of [icode]PyQt4[/icode]. Note the Capital 'T'

Member Avatar for vegaseat
0
2K
Member Avatar for The-IT

[QUOTE=The-IT;1009754]thanks a lot man, there is just one problem, my version of ubuntu does not support any version of python higher than 2.5. awww well. at least i know now to stop trying to get this one to work and start a new project witch might work.[/QUOTE] That's not entirely …

Member Avatar for jlm699
0
3K
Member Avatar for c_crash

1) This program has no indentation. To preserve formatting on this forum you must wrap your code in code tags. However after looking closer at your post it appears that your code has no indentation even in its original form. 2) You need to [learn the difference](http://www.penzilla.net/tutorials/python/functions/) between defining a …

Member Avatar for jlm699
0
131
Member Avatar for Kruptein

[QUOTE=Kruptein;998549]the progress bar only shows 100% and doesn't progress at all..[/QUOTE] A progress bar is only useful if you're actually progressing through something. The steps that happen before you send the 100% to the progress bar are like going so fast that you can't see the "progress" of your function. …

Member Avatar for Kruptein
-1
157
Member Avatar for mohankumar554
Member Avatar for jlm699
-1
136
Member Avatar for adunham1

There's no need to split the string, just simply iterate over it and perform your counting. To make a string upper case use the [icode]upper[/icode] function.

Member Avatar for pysup
-1
115
Member Avatar for pelupelu

[QUOTE=pelupelu;1005631]I am trying to compute some lexical statistics from a given text. For instance, how many lines, sentences, words, how many times a given character is repeated. Can anyone help me with this?[/QUOTE] Yes this is easy to do in python. A quick way to get the number of lines …

Member Avatar for vegaseat
0
277
Member Avatar for vipints

[QUOTE=vipints;1006149]Hi all, I am using scipy.io for switching from python to matlab. here is my list of list in python code = [[[1, 2], [3,4], [5, 6]], [[7, 8], [9, 10]]]. I want to convert this to matlab format. For that I used a code scipy.io.savemat('/tmp/out.mat', mdict={'Num': (code[0], code[1])}) [/QUOTE] …

Member Avatar for vipints
0
355
Member Avatar for khaos64

How about using a dictionary instead of two separate lists/tuples: [code=python] >>> user_dict = {} >>> user_dict['user1'] = 'passwd1' >>> user_dict.get('user2') >>> user_dict.get('user1') 'passwd1' >>> [/code] As you can see, by using the get function, we can test whether a user name is in the dictionary or not. If the …

Member Avatar for khaos64
0
273
Member Avatar for Joe Hart

I'm posting this for others so they can see what your input file actually looks like. [QUOTE]Study transfer. From FMPP_EXA To FPL_IMA . Transfer level - 1000.0 MW Violations report ordered by transfer capability. Total 3 violations FCITC TDF LODF <--------- Limiting constraint ---------> <--------- Contingency description ---------> Ncon PreShift …

Member Avatar for Joe Hart
0
90
Member Avatar for DEATHMASTER

Why don't you try something like this: [code=python]from string import letters # Upper letters only letters = letters[26:] c_string = raw_input("Enter desired sentence to convert: ") cs_string = 5 ci_string = cs_string % 26 upper_string = c_string.upper() for ch in upper_string: lett_idx = letters.find(ch) if lett_idx != -1: lett_idx -= …

Member Avatar for jlm699
0
183
Member Avatar for tgreco
Member Avatar for tgreco
0
493
Member Avatar for tweak

There's a typo in [ICODE]MyListCtrl[/ICODE] should be parent not paent. You should also have a comma (,) not a period (.) between id and pos. Additionally, how are you adding the ListCtrl to your window? You should be using a sizer. Refer to [URL="http://www.daniweb.com/forums/post650657.html#post650657"]this example by ZZucker of a ListCtrl[/URL]. …

Member Avatar for tweak
0
169
Member Avatar for jcmeyer

This is certainly not the only solution but postgresql can easily handle multiple users (like I assume most other RDMs can). The psycopg2 module is what I've used in the past for postgres but I know there are a few others out there.

Member Avatar for ov3rcl0ck
0
235
Member Avatar for klabak85

[QUOTE=klabak85;994546]what I'm passing into readComments() is actually the file object[/QUOTE] If that is the case then there's no reason to open it again. Simply iterate over the file object

Member Avatar for jlm699
0
131
Member Avatar for OneDreamCloser

It's hard to help you without the full traceback of the error but here's my two cents: You're parsing the file contents incorrectly. What you should be doing is splitting each line at the tab character to get time stamp, port number, then the remaining string of floats. At this …

Member Avatar for OneDreamCloser
0
163
Member Avatar for s.praneeth

[QUOTE=s.praneeth;993708]can anybody help me with this program i would be grateful[/QUOTE] Sure, but the answer depends on which version of Python you're using. You'll be using [icode]input()[/icode] (Python 3.X) or [icode]raw_input()[/icode] (Python 2.X) to prompt the user for input. You'll also want to make sure you're restricting the user's input …

Member Avatar for jlm699
0
339
Member Avatar for simonches

[QUOTE=simonches;991934]but i just can't figure out how to make it work. can anybody help me?[/QUOTE] You were very close: [code=python] def one(s): if s == '': return [s] else: ans = [] if s[1:] == '': return ans for o in one(s[1:]): ans.append(prevLetter(s[0])+o) ans.append(nextLetter(s[0])+o) return ans[/code] You never made use …

Member Avatar for simonches
0
158
Member Avatar for racshot65

Your method of finding primes is flawed. Try 25, 35 and 49. None of those numbers are prime and it says that they are. Fix your indentation and your algorithm and then try to loop it again. I suggest using a function.

Member Avatar for jlm699
0
119
Member Avatar for KernMilestone

[QUOTE=sneekula;872224]A man is smoking a cigarette and blowing smoke rings into the air. His girlfriend becomes irritated with the smoke and says, “Can’t you see the warning on the cigarette pack? Smoking is hazardous to your health!” To which the man replies, “I am a programmer. We don’t worry about …

Member Avatar for quicktpgo
0
553
Member Avatar for Stefano Mtangoo
Member Avatar for sab786

[QUOTE=sab786;944371]Now what i wish to do is read a file, use a dictionary to search lines, and then get these lines and write to a new out put file. Is that possible?[/QUOTE] That is how I interpret your question, so let me know if I read it wrong. To read …

Member Avatar for willygstyle
0
147
Member Avatar for fallopiano

[QUOTE=fallopiano;954679][CODE]Traceback (most recent call last): File "<pyshell#59>", line 1, in <module> return_mouse_slope( [100,100],[154,129]) File "C:/Documents and Settings/Owner/Desktop/rewrite project warp/lib/maths.py", line 15, in return_mouse_slope dist(mouse_pos,[mouse_pos[0],object_pos[1]]) ) ValueError: math domain error[/CODE] I'm not able to pass mouse_pos[0] and object_pos[1] to the dist function. Is python not able to pass arguments (in this …

Member Avatar for sneekula
0
215
Member Avatar for rajivgupta1107

If you implement glob you can use unix-style path completion ie [icode]glob.glob('*2009*.txt')[/icode]

Member Avatar for jlm699
0
93
Member Avatar for sallas07

Yes. You can use [icode]open[/icode] to open a file and return the file handle. Note that some formats (ie, .doc) are not "flat" text files, meaning they may have some binary data, markup, etc. You'll need to take that into account on a per-file basis.

Member Avatar for jlm699
0
111
Member Avatar for blah32

What do you mean by "combine" ? Or do you mean compare? If the latter, you simply compare each of their attributes, and then return each value combined with a logical [icode]and[/icode]. Some thing like: [code=python] return A.a == B.a and A.b == B.b and A.c == B.c ... etc. …

Member Avatar for jlm699
0
61
Member Avatar for Dan08
Re: Mail

Yup. smtplib is what you want. Just search this forum and you'll find boat loads of solutions.

Member Avatar for Dan08
0
252
Member Avatar for Stefano Mtangoo

Reference this page: [url=http://docs.python.org/lib/module-pdb.html]Python DeBugger (PDB)[/url]

Member Avatar for Stefano Mtangoo
0
118
Member Avatar for Dan08

[QUOTE=Dan08;950994]Ive been searching on google but I cant find an .exe or a .zip file, for example Pmw.exe or Pmw.zip. But I could find loads of tar.gz files, does this means that I cant have it, of course winzip cant open a file that is made for unix systems. What …

Member Avatar for Dan08
0
589
Member Avatar for southafrica1

You should be running py2exe as such: [icode]python setup.py py2exe[/icode] you'll want to make sure you're inside the directory where both files are located. Also your console item should be: [icode]console = [{"script": 'Hello.py'}] )[/icode]

Member Avatar for shibby
0
708
Member Avatar for Mathhax0r

[QUOTE=woooee;948931]I use multiprocessing/pyprocessing, not threading[/QUOTE] woooee: I've seen you mention this before. What makes you choose multi-process over multi-threads? I don't use either, so I'm just wondering if you see a particular advantage in one over the other.

Member Avatar for woooee
0
115
Member Avatar for nunos

[QUOTE=nunos;949263]I guess I will have to do the .0 'trick'. Maybe some other folk will know a way. Thanks wildgoose for your help.[/QUOTE] You could do this: [code=python] float(4)/5 [/code] Or if you wanted to perform the [icode]from __future__ import division[/icode] and still get integer returns you could simply turn …

Member Avatar for nunos
0
186
Member Avatar for flipjoebanana

Simply use the repr command: [code=python] >>> print(repr(s)) "'Quote Example'\tby person\n" >>> print(s) 'Quote Example' by person >>> [/code]

Member Avatar for zachabesh
0
117
Member Avatar for nunos

[QUOTE=nunos;949062](a & b): What happens with logical and? If a is false, does python evaluates b or not?[/QUOTE] No. Here's the code I just used to check this: [code=python] >>> def a(): ... print 'a' ... return False ... >>> def b(): ... print 'b' ... return True ... >>> …

Member Avatar for nunos
0
411
Member Avatar for nunos

There are two ways I know to do this: 1) Use an absolute path, ie instead of simply [icode]some_file.xls[/icode] specify [icode]"C:/Documents and Settings/UserName/My Documents/some_file.xls"[/icode] 2) Change the current working directory using [icode]os.chdir(desired_path)[/icode]. You can also check your current working directory using [icode]os.get_cwd()[/icode]

Member Avatar for nunos
0
195
Member Avatar for kessenchu

In order to better help you, you'll need to help us (the other forum members). Clearly presenting your problem will allow us to quickly scan your post and answer your question. In order to achieve this, you must use code tags when posting any code/traceback in this forum. By doing …

Member Avatar for jlm699
0
523
Member Avatar for darangho

I believe you can specify the second index as END... refer to the text widget indices guide [URL="http://infohost.nmt.edu/tcc/help/pubs/tkinter/text-index.html"]here[/URL]. These mostly seem to be tk constants, but let me know if that is a misconception.

Member Avatar for bumsfeld
0
130
Member Avatar for princessotes

[QUOTE=princessotes;947322][code]import thermodynamics oxygen={'A':31.32234, 'B':-20.23531, 'C':57.86644, 'D':-36.50624, 'E':-0.007374, 'F':-8.903471, 'G':246.7945, 'H':0.000000,'EnthalpyTempZero':8.68, 'frequency':1580.19, 'EDFT':-4.9316435} Oshomate= oxygen['A'], oxygen['B'], oxygen['C'],oxygen['D'], oxygen['E'],oxygen['F'],oxygen['G'],oxygen['H'] print EntropyO EnthalpyEntropyO = thermodynamics.EnthalpyEntropy(EnthalpyO,oxygen['EnthalpyTempZero'], EntropyO, temperature) [/code] When I run the scripts, it gives an error message "NameError: global name 'A' is not defined". How can I get the module to access …

Member Avatar for bumsfeld
0
124
Member Avatar for SoulMazer

[QUOTE=SoulMazer;944811]Because if I just replace T = Test() with T = Test(myapp), the argument it pass to "__init__", not "run". How would I go about doing this?[/QUOTE] There might be a smarter way of doing this, but you could store those variables in a member at the __init__ function and …

Member Avatar for SoulMazer
0
156
Member Avatar for zachabesh

[QUOTE=zachabesh;946904]Hi all, I'm trying to mimic an html form that calls a script on the web. When I put the form together on a page, it works, and I was wondering if there was a way I could "scrape" this post request and see what I'm missing when I try …

Member Avatar for zachabesh
0
99
Member Avatar for kenji

I'm not sure what programming questions the dietel book poses, but when I learned Python I found the exercises included in [URL="http://diveintopython.org"]"Dive into Python"[/URL] immeasurable with how much they helped me. This book is geared more towards those with prior programming experience. They assume you understand the concepts of variables, …

Member Avatar for Stefano Mtangoo
0
69

The End.