You are assigning the value to a local namespace, which is deleted once the function has been completed. To keep the value around, change "hello" to "self.hello ".
For more information on namespace's, go here:
http://docs.python.org/tut/node11.html#SEC TION00112000000 00000000000
User Profile
Collapse
-
in my experience, if you plan on using the object, string, etc more then once, assign it to a variable, else theres no need.Leave a comment:
-
but python *does* override it. It defines the first __init__ function and then, overrides it, when you define the second __init__ function.
its not a matter of being OO, its a matter of using the same name.Leave a comment:
-
Catching a message sent to python by VB function SendMessageByString
Hello.
I was wondering if any of you have ever done this before or could point me in the right direction.
[code=vb]sub test()
hWnd = API_FindWindow( "ConsoleWindowC lass", "Python")
SendCommand "/echo -a " & hWnd
iMsg = "0x000C"
wParam = "0&"
lParam = "test"
MyValue = API_SendMessage ByString(hWnd,... -
[CODE=python]print "Hello " + " ".join(["user %i," % (i) for i in range(1,1001)])[/CODE]Leave a comment:
-
Sorry for taking so long to reply, been away from home for a few days.
Yes, Timers only execute once. I suppose you can get around this by making your own class that uses the Timer object, and repeats the timer a certain ammount of times.Leave a comment:
-
Theres probably a more elegant way, or even, a built in function, but here it goes. This checks an entire string if every character is in the standard ascii tablfor the extended ascii table, you will need to extend the range of the "ascii" list.
[code=python]>>> ascii = [chr(c) for c in range(128)]
>>> def is_ascii(string ):
... for character in string:
... if not character...Leave a comment:
-
the Timer object counts down. For example, threading.Timer (60.0,whatever) .start()
would wait 60 seconds than execute whatever.
the example you provide is only waiting 1 second before executing, may seem almost instantanious.Leave a comment:
-
It did indeed give me some ideas, and they work for what I needed, thank you....Leave a comment:
-
matching x% of a string using REs?
I was wondering if it is possible to match string1 to x% of string2 using a re. I'm not sure how I would implement this exactly if it can be done, but what im ultimately looking at is it being able to detect if a string matches another string to like 70% (made some typos?)
Also, do you experts have any links for where I can understand how REs work, in python, and more exactly, in general? so far I've been using this:
... -
Modem driver?
Hello
I'm in the process of switching a older computer from Windows XP to Ubuntu (7.10).
I was wondering if there are any drivers for this particular modem, although I have heard that linux drivers for modems are rare.
"Generic 56K HCF Data Fax Modem"
now its an older computer, so I don't plan on putting a ethernet cable in it. I just want to try a few things with Ubuntu before... -
Thanks for your help,
I went and asked the developer of icechat about COM and he told me I could use DDE to connect to it, and now I have access to the scripting engine within it via the python dde module.Leave a comment:
-
Sending data from one application to another
Hello,
I'm trying to figure out how I would send data (most likely a string) from a script (written in python) to a program on windows xp.
I posted this here instead of the python forum because its not really to do with python, more to do with windows. How do two completely unrelated applications talk to eachother? What would I need to know in one application to find the other application? Does anyone have a link to... -
"Map" software?
Lately I've been thinking of trying to make a map for a game I play. The current maps are all images, they are basically just tiles each. I'd want to be able to have each tile its own small image so i could show information about it.
I was wondering if there is any already developed software that would make this easier. Someone told me to try out pygame, but I've never dealt with it so I don't really know how it works, what... -
i think this is what you want...:
[code=python]if x < 0:
x = 0[/code]Leave a comment:
-
Basically, here:
[code=python]
f = open('see.txt', 'r')
data = '\n'.join(f.rea dlines())
f.close()
# right here is where you would modify the data -- encrypting it however you want.
f = open('see.txt', 'w') # mode "w" will overwrite the file's contents.
f.write(data)
f.close()
#and you're done.
[/code]
I think this is all right but...Leave a comment:
-
It's because your code is executed everytime it is imported. enclosing it in a function would fix the problem.
so change
[CODE=python]
import urllib
import re
page = 'http://www.sec.gov/cgi-bin/browse-edgar?company=& CIK=&type=10-Q&owner=include &count=100&acti on=getcurrent'
raw = []
for line in urllib.urlopen( page):
if '<td bgcolor="#E6E6E 6"...Leave a comment:
-
Yes, this is the right way (as in, it all works). This is actually similar to what I used when learning about classes. More expert users can give you more examples, but for now it should suffice that your on the right path....Leave a comment:
-
Thanks for those, I *must* remember the timeit module.
At the time I thought it was just lag (I was using the for loops vs while loops in my irc bots, with 3 channels spamming it on purpose) but now it know for sure.
Thanks again,
Will.Leave a comment:
-
I have a question thats not exactly related to the original topic, but is sorta related to the new name of the topic :P
are there any differences in speed when executing a for loop or a while loop? It seems to me that for loops complete faster but I have no real way of testing it, I don't think. Was wondering if others experianced the same thing.Leave a comment:
No activity results to display
Show More
Leave a comment: