2,646 Posted Topics

Member Avatar for ping24

Did you try this [code=python] import webbrowser webbrowser.open(my_url) [/code] ?

Member Avatar for ping24
0
170
Member Avatar for tzushky

If you want to wait for a thread, the best way is to use the method [icode]Thread.join[/icode], so you do this [code=python] my_thread = Thread(target=...) my_thread.start() do_some_stuff() my_thread.join() [/code]

Member Avatar for tzushky
0
171
Member Avatar for Jadellll

You can also visit this site [url]http://pydoc.org/[/url] and fill the form with [code]floor[/code] to discover it's in the math module ...

Member Avatar for Gribouillis
0
152
Member Avatar for JA5ONS

This error means that the variable [icode]self[/icode] is not defined when the program reaches line 87 in your file. In order that [icode]self[/icode] be defined at this point you must either 1) put line 87 in a function where [icode]self[/icode] is a parameter, like [code=python] def myFunction(self, other_arguments): self.Entry = …

Member Avatar for JA5ONS
0
93
Member Avatar for Peter_Saumur

didn't you try to parse your xml file with a standard module like [icode]xml.dom.minidom[/icode] ? You just need to write [icode]parse("C:/infile.xml")[/icode] and you get a Document object from which you can extract your data...

Member Avatar for Peter_Saumur
0
87
Member Avatar for Dekudude

You could add [icode]inp = list(inp)[/icode] as the first line in your function. Also you should avoid using names like 'bool', 'array' or 'string' (type or module names) as variable names :)

Member Avatar for shadwickman
0
124
Member Avatar for slendergreen

It would be easier if we could see the python line which runs the system call. A possible solution to your problem is to start the system call without waiting for it's completion, using [icode]subprocess.Popen[/icode] (see [url]http://docs.python.org/lib/node533.html)[/url]. Then, once you have a child process running, print it's output with a …

Member Avatar for Gribouillis
0
126
Member Avatar for Gribouillis

In the Perl language, you can fork a child process with the following syntax [code=perl] open CHILD, " | programA | programB | program C"; print CHILD "this is an example input"; [/code] (at least, you can do this under linux). This statement starts 3 processes in fact; programA, B …

Member Avatar for slate
0
229
Member Avatar for agibbons

folders are easy to identify, use the function [icode]os.path.isdir()[/icode]. look if functions in [icode]os.path[/icode] suffice to your needs :) Also for common path operations, there is a nice Path class which exists at python.org. It was rejected as a standard class in python, but it can be useful. Look here …

Member Avatar for slate
0
316
Member Avatar for dmlandrum

like this [code=python] table = [] for i in range(0,1001): x = (i * .004) - 2 y = math.tanh(x) table.append(y) [/code] for example :)

Member Avatar for dmlandrum
0
114
Member Avatar for bimaljr

You can filter the list like this [code=python] file_count = len([f for f in os.walk(".").next()[2] if f[-4:] == ".txt"]) [/code]

Member Avatar for bimaljr
0
8K
Member Avatar for OffbeatPatriot

I give you a possible pattern (untested) [code=python] from subprocess import Popen from threading import Condition import os import signal self.user_condition = Condition() ... self.user_condition.acquire() try: while True: child = Popen("path/to/executable", *arguments) #http://docs.python.org/lib/node537.html self.user_condition.wait() if self.user_wants_to_exit_the_loop: if self.user_wants_to_stop_child: os.kill(child.pid, signal.SIGKILL) # http://docs.python.org/lib/os-process.html#l2h-2764 elif self.user_wants_to_wait_for_child: child.wait() #http://docs.python.org/lib/node532.html break finally: self.user_condition.release() [/code] …

Member Avatar for Gribouillis
0
96
Member Avatar for Jadellll

It's because your function `revstr` prints the reversed string, but then returns None (because there is no return statement). Since your program contains `print revstr(...`, this None value returned is printed. What you should do is replace print by return in `revstr`. Note: in the forum, use (code=python) instead of …

Member Avatar for Aia
0
140
Member Avatar for flhtc

A magic trick that worked with me on such problems is [icode]self.SendSizeEvent()[/icode] when you want to refresh. See if it works for you :)

Member Avatar for flhtc
0
114
Member Avatar for rob spade

try [code] >>> print '\x1b[24;27Hs\x1b[24;27H\x1b[?25h\x1b[24;28H\x1b[24;28Hh\x1b[24;28H\x1b[?25h\x1b[24;29H\x1b[24;29Ho\x1b[24;29H\x1b[?25h\x1b[24;30H\x1b[24;30Hw\x1b[24;30H\x1b[?25h\x1b[24;31H\x1b[24;31H \x1b[24;31H\x1b[?25h\x1b[24;32H\x1b[24;32Hf\x1b[24;32H\x1b[?25h\x1b[24;33H\x1b[24;33Hl\x1b[24;33H\x1b[?25h\x1b[24;34H\x1b[24;34Ha\x1b[24;34H\x1b[?25h\x1b[24;35H\x1b[24;35Hs\x1b[24;35H\x1b[?25h\x1b[24;36H\x1b[24;36Hh\x1b[24;36H\x1b[?25h\x1b[24;37H\x1b[24;0H\x1bE\x1b[24;1H\x1b[24;37H\x1b[24;1H\x1b[2K\x1b[24;1H\x1b[?25h\x1b[24;1H\x1b[1;24r\x1b[24;1HImage Size(Bytes) Date Version\r\n----- ---------- -------- -------\r\nPrimary Image : 6126444 05/25/07 T.12.09 \r\nSecondary Image : 6126444 05/25/07 T.12.09 \r\nBoot Rom Version: K.11.03\r\nCurrent Boot : Primary\r\n\r\n\x1b[1;24r\x1b[24;1H\x1b[24;1H\x1b[2K\x1b[24;1H\x1b[?25h\x1b[24;1H\x1b[24;1HProCurve Switch 2900-48G> ' [/code] On my linux console, it works. I think the special characters are instructions for the terminal. …

Member Avatar for Gribouillis
0
943
Member Avatar for ccclay

It looks like you are in a linux console. When you give the name of an executable file in the terminal, it probably tries to execute it as if it is a bash script, and you see the error messages of bash. Normally you should be able to execute your …

Member Avatar for Gribouillis
0
181
Member Avatar for Jadellll

[icode]add[/icode] is a variable which value is a function. In the same way, if you write [icode]z = 0.0[/icode], then [icode]z[/icode] is a variable which value is a float. The difference is that [icode]add[/icode] has the special property that its "callable" with the syntax [icode]add(x, y)[/icode]. You can check this …

Member Avatar for Gribouillis
0
130
Member Avatar for Seagull One

[code=python] >>> print str.replace.__doc__ S.replace (old, new[, count]) -> string [/code] hm, I think your code should raise an exception because of a missing argument. Also I suggest you set a logger for the whole conversation (see module logging). You should also modify the code so that your robot always …

Member Avatar for Seagull One
0
456
Member Avatar for EAnder

If you want to use lex and yacc tools, I think you could start with PLY [url]http://www.dabeaz.com/ply/[/url], which is a pure python implementation of lex an yacc tools by David Beazley (the author of swig). I tried it, it works quite well. The difference with a C implementation is just …

Member Avatar for Gribouillis
0
115
Member Avatar for lllllIllIlllI

I googled and after some time, I discovered this link: [url]http://www.rutherfurd.net/python/sendkeys/[/url] . If you test it, let us know if it works. I'd like to find an equivalent module on linux. There is also a perl module named GUITest, which exists with a windows and a linux version. With some …

Member Avatar for lllllIllIlllI
0
388
Member Avatar for lllllIllIlllI

On windows, I was able to shutdown the system with [code=python] import os os.system("shutdown -s") [/code] On linux, it was [code=python] import os os.system("sudo shutdown -h now") [/code] Note that normaly on linux, only the superuser can shutdown the machine with 'shutdown'. Other users must be allowed to do so …

Member Avatar for Gribouillis
0
1K
Member Avatar for dmpop

An extreme solution: a class to escape any set of characters (reuse freely) [code=python] #!/usr/bin/env python # escaper.py # a class to escape characters in strings import re class Escaper(object): def __init__(self, chars): self.pat = re.compile("[%s]" % re.escape(chars)) def __call__(self, data): return self.pat.sub(lambda c: "\\"+c.group(0), data) if __name__ == "__main__": …

Member Avatar for dmpop
0
114
Member Avatar for dmpop

A simple way to do this would be to write a small GUI code, using the wx.TextEntryDialog widget. I suggest that you visit this link [url]http://wiki.wxpython.org/AnotherTutorial#head-2e6716d7887279f22b0ffa57dc03278ea4ed8f85[/url] and paste the code section just below, and then drop most of the methods, but the method [icode]def textentry[/icode]. In the text entry, you …

Member Avatar for dmpop
0
169
Member Avatar for Seagull One

At first sight, the problem is that you refer to a variable [icode]self[/icode] outside of a class block. In the loop [icode]while 1[/icode] at the end of the file, it should probably be [icode]speechReco.items[/icode]. Also shouldn't the function [icode]def SetItem[/icode] be a method of [icode]class speechRecognition[/icode]? The loop [icode]while Greeting …

Member Avatar for Seagull One
0
1K
Member Avatar for leegeorg07

Here is a better way to handle flow of control :) [code=python] def youWantToAddAPerson(): return int(raw_input("Do you want to add a new person (0 or 1) ? ")) def getThePersonName(): return raw_input("What is the name of the person ? ") def getThePersonNumber(): return raw_input("What is the number of that person …

Member Avatar for leegeorg07
0
107
Member Avatar for friendklay

Here is a way to swap characters [code=python] import re swap_pat = re.compile(u"A(?:B|C|D)") def swap(swap_match): s = swap_match.group(0) return s[1] + s[0] def swap_sub(theString): return swap_pat.sub(swap, theString) second_pat = re.compile(u"\u1013(.*)\u102C") def second(second_match): middle = second_match.group(1) return u"\u1001%s\u102B" % middle def second_sub(theString): return second_pat.sub(second, theString) if __name__ == u"__main__": s = …

Member Avatar for friendklay
0
346
Member Avatar for monstro

May be you could try this [code=C++] catch (...) { if(PyErr_Occurred()) { PyErr_Print(); boost::python::object traceback(boost::python::handle<>(PyImport_ImportModule("traceback"))); std::string err_text = boost::python::extract<std::string>(traceback.attr("format_exc")()); logErrors = "Exception caught: "; logErrors += err_text; LogMessage((char*)logErrors.c_str()); boost::python::handle_exception(); } success = false; } [/code] I don't think the [icode]sys.stderr.getvalue[/icode] exists :)

Member Avatar for monstro
0
251
Member Avatar for bikehike90

May be you can keep the same label and update it's content. There is a nice way to do this with a Tkinter variable, described in this page [url]http://effbot.org/tkinterbook/label.htm[/url]

Member Avatar for Gribouillis
0
93
Member Avatar for iamoldest

found in another forum: [code=python] >>> x = "Blah" >>> def pp(): ... global x ... x = "Hello There!" ... >>> print x Blah >>> pp() >>> print x Hello There! [/code]

Member Avatar for ZZucker
0
123
Member Avatar for chython

In python 2.5 there is a standard module [icode]sqlite3[/icode] so I'd rather use this module.

Member Avatar for woooee
0
41
Member Avatar for desm

Here the method is [icode]demonstration.number[/icode] (it's an attribute of the class, which you hide in the instances with [icode]self.number = number[/icode].

Member Avatar for desm
0
95
Member Avatar for eibwen

Here is my solution. Since you're learning python, your job is to understand the details :). [code=python] import re digits_pat = re.compile(r"\d{3}(?:[*]|$)") def digits_trans(mo): s = mo.group(0) return "%s.%s" % (s[0], s[1:]) def digits_sub(theString): return digits_pat.sub(digits_trans, theString) def addDots(fileIn, fileOut, startAt=20): fout = open(fileOut, "w") for line in open(fileIn, "r"): …

Member Avatar for Gribouillis
0
174
Member Avatar for planetPlosion
Member Avatar for desm

I write a lot of python code and almost never use global declarations :). In fact you must use a global declaration when you want to assign a value to a global variable in a function, like your line [code=python] Contacts_lbox = Listbox(f3,height=5) [/codeh however it works only if your …

Member Avatar for desm
0
2K
Member Avatar for Hogg

I give you two versions so that you can compare them [code=python] def firstLettersA(theString): theWords = theString.split() theLetters = mapl(lamda w: w[:1], theWords) theResult = ''.join(theLetters) print theWords, theLetters, theResult return theResult def firstLettersB(theString): return ''.join(map(lambda w: w[:1], theString.split())) def main(): print "This program splits the words in a sentence" …

Member Avatar for Hogg
0
6K
Member Avatar for Seachmall

There doesn't seem to be an error. This kind of errors happen sometimes with IDE like idle when a module like 'handle_input' was previously loaded and then modified, but the modified version is not reloaded by idle. However, since we don't know the context, I suggest for debugging that you …

Member Avatar for Seachmall
0
348
Member Avatar for TheOneElectroni

may be it's related to this [url]http://mail.python.org/pipermail/python-list/2004-June/268575.html[/url]

Member Avatar for TheOneElectroni
0
449
Member Avatar for skymuss

I think there are functions like [U]quote[/U] or [U]urlencode[/U] in the urllib module. I suggest you import urllib and look at the output of help(urllib) in your python console. Also search "encode url in python" with google :)

Member Avatar for Gribouillis
0
323
Member Avatar for sepiso
Member Avatar for Gribouillis
0
91
Member Avatar for sameer123

Python is open source and written in C, so in principle you should be able to extract pickling functions from the source code of python itself. It's most certainly a useless task to try to write another C function for this. Another way to hide things is to use an …

Member Avatar for sameer123
0
297
Member Avatar for FreezeBlink

There is a solution using [I]properties[/I], that is, dynamic attributes. Here is the code [code=python] class Item(object): def __init__(self, name = ""): self._name = name self._cname = None def _get_name(self): return self._name def _set_name(self, value): self._name = value self._cname = None name = property(_get_name, _set_name) def _get_creationName(self): return self.name if …

Member Avatar for Gribouillis
0
115
Member Avatar for vegaseat

I have some experience with speeding up python with swig. It allows you to access virtually any algorithm written in C or C++ from python. I used it for numerical analysis and also parsing. On such problems, this method is quit e efficient. However, the most useful feature of swig …

Member Avatar for Gribouillis
0
491
Member Avatar for tzushky

Hello. The problem with your solution is that it works only on windows. I don't know if a portable solution exists. It should be possible to use the python interface of openoffice.org for such a task (but the ooo api is quite complicated). A starting point could be [url]http://wiki.services.openoffice.org/wiki/Extensions_development_python[/url] :)

Member Avatar for Gribouillis
0
2K
Member Avatar for tzushky

Hello, Some software testing programs contain functions to simulate human interaction with GUIs. In this page [url]http://www.tizmoi.net/watsup/intro.html[/url] , there is an example of writing automatically in a running notepad application. May be you could make it write in your hyperterminal ?

Member Avatar for tzushky
0
170
Member Avatar for darkMatter2008

A solution is to keep a dictionary of the objects you reference. The dictionary would have the object's id's as keys and the object as values.

Member Avatar for Gribouillis
0
105
Member Avatar for ciuchi

How to Simplify expressions ? I need to know how to simplify expressions like these 2t2+(3+5)(4t)=, and -2t(4t-5)+(-5t2)= i need to learn how to simplify expressions step by step and if there is a website you know of that can show me how to solve simplify expressions step by step …

Member Avatar for ciuchi
0
1K

The End.