761 Posted Topics
Re: 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 … | |
Re: [URL="http://tinyurl.com/yfrt8uq"]Here[/URL] | |
Re: 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'). | |
Re: 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 ... … | |
Re: [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. … | |
Re: 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 | |
Re: 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. | |
Re: 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 … | |
![]() | Re: [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 … |
Re: 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' | |
Re: [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 … | |
Re: 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 … | |
Re: [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. … | |
Re: [url=http://docs.djangoproject.com/en/dev/intro/install/]Search the web[/url] before posting, please | |
Re: 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. | |
Re: [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 … | |
Re: [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] … | |
![]() | Re: 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 … ![]() |
Re: 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 … | |
![]() | Re: 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 -= … |
Re: Have you tried uninstalling the program and doing a fresh install? | |
Re: 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]. … | |
Re: 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. | |
Re: [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 | |
Re: 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 … | |
Re: [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 … | |
Re: [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 … | |
Re: 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. | |
Re: [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 … | |
Re: I'd suggest secure copy via ssh (scp). | |
Re: [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 … | |
Re: [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 … | |
Re: If you implement glob you can use unix-style path completion ie [icode]glob.glob('*2009*.txt')[/icode] | |
Re: 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. | |
Re: 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. … | |
Re: Yup. smtplib is what you want. Just search this forum and you'll find boat loads of solutions. | |
Re: Reference this page: [url=http://docs.python.org/lib/module-pdb.html]Python DeBugger (PDB)[/url] | |
Re: [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 … | |
Re: 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] | |
Re: [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. | |
Re: [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 … | |
Re: Simply use the repr command: [code=python] >>> print(repr(s)) "'Quote Example'\tby person\n" >>> print(s) 'Quote Example' by person >>> [/code] | |
Re: [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 ... >>> … | |
Re: 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] | |
Re: 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 … | |
Re: 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. | |
Re: [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 … | |
Re: [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 … | |
Re: [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 … | |
Re: 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, … |
The End.