761 Posted Topics

Member Avatar for gunbuster363

[QUOTE=gunbuster363;1046437]Here is my code. If I use forloop to write, it got error: Traceback (most recent call last): File "m.py", line 20, in <module> f.write(tag[i].string) TypeError: argument 1 must be string or read-only character buffer, not None HOWEVER, if I don't use for loop, instead write as : f.write(tag[1].string) it …

Member Avatar for gunbuster363
0
151
Member Avatar for gunbuster363

What platform is this? Windows XP, Ubuntu Linux, Mac OSX, etc? There's a number of possibilities here. Most likely the folder you're working in doesn't give you write permissions.

Member Avatar for gunbuster363
0
124
Member Avatar for XLL

In the future, please use code tags when posting code. It will allow the forum members here to read your post easily and will give you answers quicker (and of better quality). Now I will repost your code with code tags so you can see the difference: a=2 b=3 def …

Member Avatar for jlm699
0
82
Member Avatar for jex89

I'd look into beautifulsoup if you're looking to break this thing down into an object hierarchy type structure. I haven't used it much, but I know there's plenty of examples on this site of how to implement it.

Member Avatar for jlm699
0
75
Member Avatar for Xydric

The method [ICODE]os.getcwd()[/ICODE] can only ever return a single string. There's ever only one current working directory, so when you're saying [ICODE]for d in os.getcwd()[/ICODE], you're actually iterating over the string character by character. What you really want is just [ICODE]generators = os.walk(os.getcwd())[/ICODE]

Member Avatar for jlm699
0
111
Member Avatar for xm1014

[QUOTE=xm1014;1043038]Ah ha! That worked! Now, since you're putting it in a list to sort the values, is there also a way to separate those values you are sorting on into a list by themselves?[/QUOTE] Is this what you mean? [code=python] >>> my_dict = {'a':1, 'b':2, 'c':3} >>> my_dict.keys() ['a', 'c', …

Member Avatar for vegaseat
0
445
Member Avatar for pyprog

[QUOTE=pyprog;1043034]Can you help?[/QUOTE] Why, yes! This case would be a good one to use the dictionary's get method, which will allow you to determine if the key is already in the dictionary or not, and act accordingly. [CODE]def file_to_dict(fname): f = open("file.txt") d = {} for line in f: columns …

Member Avatar for pythopian
0
1K
Member Avatar for pyguy420

[QUOTE=pyguy420;1043071] [CODE] if player[0] != "r" or player[0] != "p" or player[0] != "s": print "incorrect choice entered" [/CODE][/QUOTE] Just a minor logic error. This should be: [CODE] if player[0] != "r" and player[0] != "p" and player[0] != "s": print "incorrect choice entered" [/CODE]

Member Avatar for vegaseat
0
83
Member Avatar for rasizzle

If you search the forum you'll see this question has been asked a bajillion times. [URL="http://www.daniweb.com/forums/post1041001.html#post1041001"]Here's an example from earlier today[/URL].

Member Avatar for vegaseat
0
122
Member Avatar for plzhelp

[QUOTE=plzhelp;1043305]is it possible to search a multi dimensional list for a certain letter then print out where that letter is? i know u can use list.index() to find a letter but i could figure out how to do it with multi dimensional lists. thx in advance[/QUOTE] Something like this perhaps: …

Member Avatar for pythopian
0
93
Member Avatar for Linky

> Anyone know how to take the readlines() blob and split it up into an array? The function `readlines()` already gives you an "array" (it's list in Python). So I guess that part's solved Welcome to the forum Linky. Please, in the future use code tags (or any other appropriate …

Member Avatar for Linky
0
252
Member Avatar for mitsuevo

Create an empty list: [code=python] my_list = [] [/code] Create a list of specified length with all "blank" values: [code=python] my_list = [''] * my_length [/code]

Member Avatar for mitsuevo
0
10K
Member Avatar for mitsuevo

You can stop using IDLE and just run your code in the console, which retains the usage of Ctrl+C (I believe that IDLE tries to catch Ctrl+C)

Member Avatar for jlm699
0
110
Member Avatar for PixelHead777

[QUOTE=PixelHead777;1037962]It would be nice if the GUI had color-coded parentheses, to show groupings... or better yet, shading of a similar method...[/QUOTE] Why not use one that does then? I use Notepad++, but I know that even python-specific IDEs like PyScripter have parenthesis highlighting, etc. In fact, PyScripter will have a …

Member Avatar for woooee
0
229
Member Avatar for Felicidas

Here's some examples of converting between strings, lists, lists of strings, and ints using [ICODE]list[/ICODE], [ICODE]str[/ICODE] and [ICODE]int[/ICODE]: [code=python]>>> usr_inp = '123456' >>> usr_inp2 = '1,2,3,4,5,6' >>> list(usr_inp) ['1', '2', '3', '4', '5', '6'] >>> usr_inp2.split(',') ['1', '2', '3', '4', '5', '6'] >>> list(usr_inp)[4] '5' >>> int(list(usr_inp)[4]) 5 >>> str(int(list(usr_inp)[4])) …

Member Avatar for vegaseat
0
197
Member Avatar for AutoPython

[QUOTE=ShadyTyrant;1038086]You are using the input() function instead of using raw_input(). [/QUOTE] He also is using parenthesis in his print statements. I'd surmise that he's using Python 3.0, in which case the use of input is the only option. ([ICODE]input [/ICODE]has been replaced by [ICODE]raw_input[/ICODE]) EDIT: Additionally, I tried his code …

Member Avatar for jlm699
0
175
Member Avatar for laxter17

[QUOTE=laxter17;1038230]And this what I need to do for the third function: The third function (call it "sum3") computes and prints the answer using a "while" loop. In some respects the code is similar to the "for" loop of part 2 above. However, unlike a "for" loop, you have to initialize …

Member Avatar for ShadyTyrant
0
168
Member Avatar for tdeck

[QUOTE=tdeck;1037090][CODE]result = [(key, value)for key in dict.keys(), value in dict.values()][/CODE] ... [CODE]result = [(dict.keys[i], dict.values[i]) for i in range(1, len(dict))] [/CODE][/QUOTE] Just please note that in Python, we use the built-in function [ICODE]dict()[/ICODE] to convert certain objects to a dictionary. If you used the above code, you would lose this …

Member Avatar for jlm699
0
328
Member Avatar for newportking

def main(): print "This program illustrates a chaotic function." print "Please enter two numbers between 0 and 1." x = input ("Enter first number: ") y = input ("Enter second number: ") print print "input", x, y print "-----------------" for i in range (8): x = 3.9 * x * …

Member Avatar for newportking
0
118
Member Avatar for P00dle

[QUOTE=P00dle;1037538] The beginning of every record looks like this: MSUBUGA JIMSON P O BOX 21273 GABORONE (Obviously they are all different, but always have 3 values on 3 lines.) The end looks like this: P107.17 P0.00 P225.08 P0.00 P332.25 (The numbers always vary, but there are always 5) [/QUOTE] So …

Member Avatar for jlm699
0
321
Member Avatar for kisan

[QUOTE=kisan;1036740]IT was quite helpful. so in case of palindromes how can we remove the symbols and capital letters using .upper and replace function?? for example "Madam, in Eden I'm Adam!"[/QUOTE] Use replace to swap out the punctuation for an empty string (''). Then use upper on both the original and …

Member Avatar for Gribouillis
-1
193
Member Avatar for ihatehippies

[QUOTE=ihatehippies;1032799]Here's my problem. I wx application that works great until I close it (leaving the idle editing session open) and then restart it.[/QUOTE] Your real problem is that you're using IDLE. Your best bet is to switch to a better-featured (not to mention better-designed) IDE and run your scripts directly …

Member Avatar for ihatehippies
0
140
Member Avatar for PixelHead777

[QUOTE=PixelHead777;1023070]... It won't even import curses.[/QUOTE] That's because curses isn't available for Windows. The documentation should probably specifically say that, but they actually just tip-toe around that fact:[QUOTE]The curses module provides an interface to the curses library, the de-facto standard for portable advanced terminal handling. While curses is most widely …

Member Avatar for PixelHead777
0
320
Member Avatar for sravan953

How about instead of just generating an arbitrary StaticText object, assign it to a persistent member of your class (let's call it [ICODE]self.login_status_text[/ICODE]). Then instead of generating it each time, simply update the contents to the proper string (It's been years since messing with wxPython but if I remember correctly …

Member Avatar for pythopian
0
619
Member Avatar for sneekula

[QUOTE=sneekula;916520]I am still rather new to the Linux OS and need some detailed advice on the installation of Python3.1 on my Ubuntu machine. Python3.1 is not in the Ubuntu package repository yet.[/QUOTE] If you perform an [ICODE]apt-cache search python | grep -E "31|3\.1" [/ICODE] do you get any hits? Alternately …

Member Avatar for pdxwebdev
0
1K
Member Avatar for nevets04

This code has a lot of room for improvement. It would benefit you to read up on [URL="http://docs.python.org/tutorial/classes.html"]classes [/URL]and [URL="http://docs.python.org/tutorial/controlflow.html#defining-functions"]functions[/URL], as well as [URL="http://www.python.org/dev/peps/pep-0008/"]PEP 8[/URL] (recommended Python coding guidelines). Maybe you should challenge yourself to improve the style of your coding and make your program more readable. Also it would …

Member Avatar for nevets04
-2
312
Member Avatar for thehivetyrant

[QUOTE=thehivetyrant;1027256] [code] def getpos(): r1 = x,y = 100,100 r2 = x,y = 800,800[/code] i get the error: [icode][I][COLOR="Red"]Traceback (most recent call last): r1.step(r2.getPos()[0],r2.getPos()[1]) AttributeError: r2 instance has no attribute 'getPos'[/COLOR][/I][/icode] I have defined getPos() for both r1 and r2 (my objects), so why do i get that error? Any …

Member Avatar for thehivetyrant
0
863
Member Avatar for Megabyte89

[QUOTE=Megabyte89;1026776]Thanks to anyone who can lend help with this.[/QUOTE] You've simply forgotten to put the [B]value[/B] of [ICODE]results[/ICODE] into the string. Instead you mistakenly typed the name results. Here's how you should use string formatting to add the value: [CODE=python] db.execute("SElECT fname, lname, phone, address, email from contacts WHERE lname …

Member Avatar for strider1066
0
214
Member Avatar for twoshots

[QUOTE=twoshots;1024183]No, wait, I'm an idiot :) It's x = Stuff(), not x = Stuff of course. Meh.[/QUOTE] You're not an idiot, you're learning! It's good that you've solved your own problem. I actually just read an article about how a programming instructor put a teddy bear on his desk. When …

Member Avatar for twoshots
0
122
Member Avatar for sravan953

[QUOTE=sravan953;1027217]Hey All, I have made a program called "Pymailer", I have even made a GUI version... now what I want to do is to convert it to .exe format... how do I do it? I googled for some info, but in vain![/QUOTE] The same way you create any .exe, using …

Member Avatar for sravan953
0
1K
Member Avatar for iamai

[QUOTE=iamai;1027076]I want to convert an integer to a hexadecimal string examples lets say i have an integer value 1 i want to convert it to 0001 integer value of 16 => 0010 245 =>00F5 and so on the string must have a length of 4 digits[/QUOTE] It will be way …

Member Avatar for iamai
0
635
Member Avatar for aot

If you're looking for native-looking windows apps you'll want to go with wxPython. This is a Python class wrapper for the wx.widgets toolkit, which is cross-platform and extremely powerful. There's a sticky in this forum with tons of examples of wx code. And [URL="http://wxpython.org"]here's[/URL] where you can download the modules, …

Member Avatar for jlm699
0
106
Member Avatar for nevets04

The best beginner's language is Assembly code. It will teach you how amazingly convenient a high level language like Python is. That is sarcasm, but just read my response to this post in the other forum

Member Avatar for vegaseat
0
215
Member Avatar for lrh9

[QUOTE=lrh9;1024753]the poorly coded "if x != 1 and x != 2 and x != 3"[/QUOTE] Why yes, that is poorly coded. Good thing this is Python! [code=python] >>> x != 1 and x != 2 and x != 3 True >>> x not in [1,2,3] True[/code] Data validation is extremely …

Member Avatar for paddy3118
0
362
Member Avatar for A_Dubbs

In the if statement you are using w[i+5]. This means that you need to make sure the maximum i plus 5 does not go out of bounds for the string. Let me demonstrate: [code=python] >>> w = 'aabbccdd' >>> print len(w), len(w) - 5 8 3 >>> range(3) [0, 1, …

Member Avatar for woooee
0
138
Member Avatar for lrh9

[QUOTE=lrh9;1025020]OK. I tested calling one object's methods from another object like so. ... Must be a bug in my actual program.[/QUOTE] Can you explain what the bug is? Each call worked and printed "This is Test2's method." What was the expected output? EDIT: I think I understand now. You're saying …

Member Avatar for lrh9
0
203
Member Avatar for simpatar

[QUOTE=simpatar;1025285]Correct, I use python3. I deleted the float infront of the input since it was causing the program to bug. But shouldnt I be able to tell python to make all variables that i put in the input to be floats? if not, how do I make them float nicely?[/QUOTE] …

Member Avatar for vegaseat
0
82
Member Avatar for nevets04

I don't see any reason why you should skip your high school's C++ classes; however realize that your high school career doesn't really impact your job opportunities as much as your college career. Learning how to program is more about a set of skills than a particular language. There are …

Member Avatar for hawash
0
198
Member Avatar for nevets04

[QUOTE=nevets04;1022470]Anyone got any ideas?[/QUOTE] [URL="http://docs.python.org/library/cgi.html#installing-your-cgi-script-on-a-unix-system"]This[/URL] should help. Don't ever underestimate the power of documentation.

Member Avatar for jlm699
0
199
Member Avatar for mohankumar554

[QUOTE=mohankumar554;1023977]hi, i want to develop small games using python on mac. so which modules /libraries i have to import . and how to proceed to develop the game... plz tell me.[/QUOTE] You'll find it all [URL="http://www.pygame.org/news.html"]here[/URL]. Download pygame, tutorials, code examples, everything. there's also a number of threads about pygame …

Member Avatar for jlm699
0
90
Member Avatar for python.noob

[QUOTE=python.noob;1022978]though i'm calling pr() function in the subclass after calling the get_details() function(which assigns value to name) it doesn't print the current value of name.[/QUOTE] Actually, it is printing the current value of name. The employee.name is always a space (' '), because you never change it. In your get_details …

Member Avatar for AutoPython
0
220
Member Avatar for srk619

You're likely getting an exception. When an exception is raised, the program quits. The best way to catch the traceback is to open your own command prompt and run the program that way. Go to Start -> Run... and enter [icode]cmd[/icode] and press Enter. This opens a windows command prompt. …

Member Avatar for snippsat
0
96
Member Avatar for hdk

It would be easier for us to help if you gave us just the barebones code that produces this abnormality. Most users won't have every single one of those modules and it would be cumbersome to traverse around to find and install them all. Are you able to see your …

Member Avatar for hdk
0
409
Member Avatar for OldGrantonian
Member Avatar for srk619

According to your explanation: [code=python]def step(x,y): pass [/code] If you need something else you'll need to explain what you're trying to do and give some context. If you really want some code written for you you'll need to provide some code for us to work from. We can't just automagically …

Member Avatar for jlm699
0
103
Member Avatar for jsw24

To do it the way you're trying to do it, use this: [code=python] >>> num = 0 >>> mylist = [] >>> >>> while num < 10: ... num += 1 ... mylist += [num] ... >>> for item in mylist: ... print item ... 1 2 3 4 5 …

Member Avatar for masterofpuppets
0
15K
Member Avatar for Kruptein

Alternately you could use modulus division like this: [code=python] >>> f = 123.456 >>> ipart = int(f) >>> fpart = f % 1 >>> ipart 123 >>> fpart 0.45600000000000307 >>> [/code]

Member Avatar for jlm699
0
262
Member Avatar for Kruptein

Or what about using chr() and then just adding 65?: [code=python] >>> def numtolet(num): ... return chr(num + 65) ... >>> numtolet(1) 'B' >>> numtolet(12) 'M' >>> numtolet(14) 'O' >>> [/code] Or the reverse: [code=python]>>> def lettonum(let): ... return ord(let) - 65 ... >>> lettonum('O') 14 >>> lettonum('A') 0 >>> …

Member Avatar for bumsfeld
0
205
Member Avatar for awa

On top of jice's comment, you don't need to import string, and it would benefit you to move your top-level code into your main function: [CODE=python]def getdata(data): listing = [] for line in data: new_line = line.split()[:2] listing.append(new_line) number = len(listing) items = listing # This is what jice added …

Member Avatar for awa
0
117
Member Avatar for saikeraku

[QUOTE=saikeraku;1013164]I never learned the "in" function yet. What if I wanted to use the index code in my code? Like the lucky[i], is there a way to do it? I haven't learned much about python yet, so I wanted to see if I can use what I've learned to finish …

Member Avatar for vegaseat
0
158

The End.