Re: [Tutor] Indentation Issue and Blind People
jim stockford wrote: > you might consider keeping your code at two > spaces and when/if the need arises to share > your code, write a little filter program that > translates the two-space indents to four. > very interesting idea to play piano notes. > how'd you do that? > Why not just use Tabs. Just one character, might be easy on Braille (know nothing about it), and almost every editor will convert from tabs to any quantity of spaces you require. Just modify your program to play the piano notes on tabs and you're done. > > On Nov 30, 2007, at 10:58 AM, [EMAIL PROTECTED] wrote: > >> Hi, >> I am just getting started with Python, as in learning the syntax for >> basic >> statements and how to write functions and all. Here is my question. >> Usually, if you are a person who is blind, you run the risk of having >> trouble keeping your code indented properly. There are ways to do it, >> but >> they are often time-consuming. Can I get a program that I can use that >> will >> take my Python code as input and make sure it is indented properly? Or, >> does Python let you write code, compile it, and indent it later? For >> anyone >> who may be interested, I have created a scheme for my screen reader >> that >> plays piano notes at indentations of two space increments. I made the >> code >> indent that way because four spaces is a lot to have on a braille >> display. >> If four spaces is more acceptable, I could globally replace two spaces >> with >> four. >> >> Thanks. >> >> Jim ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] lstrip removes '/' unexpectedly
Danny Yoo wrote: >> Hello: >> I'm seeing some strange behavior with lstrip operating >> on string representations of *nix-style file paths >> Example: > s = '/home/test/' > s1 = s.lstrip('/home') > s1 >> 'test/' ## '/test/' was expected! '/' was unexpectedly removed >> Any comments or corrective measures are welcome > > > > Hi Tim, > > Here's another example to help you see what's going on: > > ## s = '/home/test/' s1 = s.lstrip('/ehmo') s1 > 'test/' > ## > > Take a closer look at the documentation of lstrip, and you should see that > what it takes in isn't treated as a prefix: rather, it'll be treated as a > set of characters. > But then the real bug is why does it not strip the trailing '/' in 'test/' or the 'e' that is in your set? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] lstrip removes '/' unexpectedly
On Dec 3, 2007 4:29 PM, Ricardo Aráoz <[EMAIL PROTECTED]> wrote: > Danny Yoo wrote: > >> Hello: > >> I'm seeing some strange behavior with lstrip operating > >> on string representations of *nix-style file paths > >> Example: > > s = '/home/test/' > > s1 = s.lstrip('/home') > > s1 > >> 'test/' ## '/test/' was expected! '/' was unexpectedly removed > >> Any comments or corrective measures are welcome > > > > > > > > Hi Tim, > > > > Here's another example to help you see what's going on: > > > > ## > s = '/home/test/' > s1 = s.lstrip('/ehmo') > s1 > > 'test/' > > ## > > > > Take a closer look at the documentation of lstrip, and you should see > that > > what it takes in isn't treated as a prefix: rather, it'll be treated as > a > > set of characters. > > > > But then the real bug is why does it not strip the trailing '/' in > 'test/' or the 'e' that is in your set? > > Thats because you called lstrip() and not strip() which will strip only from left side. -- Aditya ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] lstrip removes '/' unexpectedly
Ricardo Aráoz wrote: > Danny Yoo wrote: > >>> Hello: >>> I'm seeing some strange behavior with lstrip operating >>> on string representations of *nix-style file paths >>> Example: >>> >> s = '/home/test/' >> s1 = s.lstrip('/home') >> s1 >> >>> 'test/' ## '/test/' was expected! '/' was unexpectedly removed >>> Any comments or corrective measures are welcome >>> >> >> Hi Tim, >> >> Here's another example to help you see what's going on: >> >> ## >> > s = '/home/test/' > s1 = s.lstrip('/ehmo') > s1 > >> 'test/' >> ## >> >> Take a closer look at the documentation of lstrip, and you should see that >> what it takes in isn't treated as a prefix: rather, it'll be treated as a >> set of characters. >> >> > > But then the real bug is why does it not strip the trailing '/' in > 'test/' or the 'e' that is in your set? > > Because it's lstrip(), the "L" meaning "left". Not strip() or rstrip(). ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] help
I recently downloaded the newer version of python, the 2.5.1 one, and when ever i try to make an input what ever i type into the brackets appears on the next line and when i try to add the next line it carries on from the input,This is what happens: I type this down: # Area calculation program >>>print “Welcome to the Area calculation program” >>>print “–” >>>print >>># Print out the menu: >>>print “Please select a shape:” >>>print “1 Rectangle” >>>print “2 Circle” >>># Get the user’s choice: shape = input(“>30 “) >30 (and then this line appears) (here i should type "# Calculate the area:" but it carries on from the above line and when i press enter i encunter an error and it all goes wrong) please help me with this problem. __ Sent from Yahoo! - the World's favourite mail http://uk.mail.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] multithread question
Dear Tutors, I have a multithread python service on a windows server, that brekas down sometimes. It is a service, that runs on a server and listen on the 9100 tcp port on three IP addresses, just as three jetdirect devices. It listens as a virtual printer, captures the content of the print jobs and makes local backups from them. It also creates a bat file, that can be used to copy the captured files to the real printers via nc. I feel that the problem is somewhere on the write_files process. The tree threads feeds the queues paralelly, and the manger.write_files() is responsible to pick the first ones and write them into local files. I have no got any idea, how may I controll to pick up them only once. I am affraid that, this function is called more times from different threads in the same time, and it could stop that thread. I have tried to place a try except into the threads itself, but it made it absolutly unstable. It was funny as it worked absolutly well in service debug mode and stoped allways started in service mode, anyway. I am also interested about that, where should I place the try except blocks in the thread. Yours sincerely, __ Janos Juhasz VirtualPrinterService.py Description: Binary data ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Problems with List Server?
I appear to be having a weird problem with the List Server. At first, email sent to this address did not appear at all. After contacting the ML maintainers only one email from me to this address go through. When I replied to the thread which the email started, it was not delivered. This is a very frustrating turn of events and I am hoping that it will be corrected soon. I wonder if anyone else is having similar problems? I suspect that this email will be delivered, but I might not be able to send another on the same thread. Any ideas? tim ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Selecting a browser
Martin Walsh wrote: > Ricardo Aráoz wrote: >> Hi, I've checked webbrowser module and so far I find no way of selecting >> a browser other than the default one. Say I want certain places opened >> with IE and others with Mozilla, and I don't want to mess with the >> user's setting of the default browser. Any tips? >> TIA > > I think one would normally use the form webbrowser.get('firefox'), on > unix systems. But if I understand correctly, the "problem" with the > webbrowser module on windows (and perhaps it is similar on a mac) is > that unless the program can be found on your system PATH, only a generic > 'windows-default' browser class is registered, which uses os.startfile, > releasing control to the os, and serves to open the url in the user's > default browser. > > If you're determined to use the webbrowser module on windows, you might > be able to do something like this: > > import webbrowser > > ffcommand = "c:/program files/mozilla firefox/firefox.exe %s &" > ff = webbrowser.get(ffcommand) > ff.open("http://www.example.com";) > > iecommand = "c:/program files/internet explorer/iexplore.exe %s &" > ie = webbrowser.get(iecommand) > ie.open("http://www.example.com";) > > I suppose you could also register them manually for later use with the > webbrowser.get(browser_name) form. > > webbrowser.register('firefox', None, ff) > webbrowser.get('firefox').open('http://example.com') > Hi Marty, thanks for your help. I've tried your suggestions but they don't seem to work for me. In W's system window I can do : C:/> S:\FirefoxPortable\FirefoxPortable.exe http://www.google.com and it will open my browser ok. But no matter what I try : "c:/program files/mozilla firefox/firefox.exe %s &" or "c:/program files/mozilla firefox/firefox.exe %s" as input to webbrowser.get() it won't work. Here's my session : >>> import webbrowser >>> ff = webbrowser.get("S:\FirefoxPortable\FirefoxPortable.exe %s &") >>> ff.open('http://www.google.com') False >>> ff = webbrowser.get("S:\FirefoxPortable\FirefoxPortable.exe %s &") >>> ff >>> ff.open(r'http://www.google.com') False >>> ff.open('') False >>> ff = webbrowser.get("S:\FirefoxPortable\FirefoxPortable.exe %s") >>> ff.open(r'http://www.google.com') False Besides looking at the Python 2.5 documentation gave me no clues. It is very poorly documented e.g. : register( name, constructor[, instance]) Register the browser type name. Once a browser type is registered, the get() function can return a controller for that browser type. If instance is not provided, or is None, constructor will be called without parameters to create an instance when needed. If instance is provided, constructor will never be called, and may be None. This entry point is only useful if you plan to either set the BROWSER variable or call get with a nonempty argument matching the name of a handler you declare. But it does not define what a 'constructor' is (I guess a function, but no clue about what it's signature or functionality should be) or what an "instance" is (but I can guess). Trouble is when you guess and things don't work you don't have a clue if the fault lies in your 'guess' or in your code. Note that it mentions 'the BROWSER variable' but does not say what it is, what it's value should be, nor any clue about it's use. Probably I lack knowledge in the subject, but hey! the whole purpose of this module is to be able to call the browser WITHOUT any knowledge of the subject. I guess I'll have to look at the code when I have a couple of free hours. I'd rather go with the 'webbrowser' module than the subprocess.Popen option, as it 'should' abstract me from browser management. Anyway if I can't advance through webbrowser I'll give your examples a try. Thanks a lot for your help. Ricardo > Personally, I would probably just cut out the middle module and use > subprocess.Popen to start the browser, after checking if it is installed > (with os.path.isfile, or similar) -- which seems to be, more or less, > what the webbrowser module does if it finds one of the predefined > browsers on your system PATH. Something like this (pseudo-code): > > browser = 'c:/program files/mozilla firefox/firefox.exe' > > if os.path.isfile(browser): > p = subprocess.Popen([browser, 'http://www.example.com']) > # if you want to wait for the browser to > # close before continuing use p.wait() here > else: > ... web browser not found ... > > For dispatching based on site (url, or some other criteria), one idea > would be to wrap something like the above in a function which accepts > the web browser program path as an argument, and then pass the function > a path appropriate for the given criteria. Here is another (untested) > example to demonstrate: > > import subprocess > import urlparse > import sys, os > > FFPATH = 'c:/program files/mozilla firefox/firefox.exe' > IEPATH = 'c:/program files/internet explorer/iexplore.exe' > > IESITES = ['microsoft.com', 'www.microsoft.com']
Re: [Tutor] lstrip removes '/' unexpectedly
>> ## > s = '/home/test/' > s1 = s.lstrip('/ehmo') > s1 >> 'test/' >> ## >> >> Take a closer look at the documentation of lstrip, and you should see >> that >> what it takes in isn't treated as a prefix: rather, it'll be treated as a >> set of characters. >> > > But then the real bug is why does it not strip the trailing '/' in > 'test/' or the 'e' that is in your set? Because lstrip strips the characters within that set, starting from the left, until it encounters a character not in that set. Then it stops. This code produces the same results, though surely more slowly. def lstrip(s, set): for x in s: if x in set: return lstrip(s[1:],set) return s JS ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] [wxPython-users] passing file name from one script to theGUI class
I do not currently have wx installed, but I can see the errors... I think some information will help you more than answers in this instance. When you 'import clases_calling', what you are doing is creating a new namespace. Inside that namespace is the class 'funct'. In your code, you call the function 'clases_calling.func_call' which does not exist because it is hidden inside of the class 'funct'. To access this function you would have to 'clases_calling.funct.func_call(self)'. This is bad practice, and defeats the purpose of using a class. Which is understandable since the class 'funct' is not necessary here. All you need is a function that will return the new filename right? So, in the clases_calling module place a 'getnewfilename' function which will return the new filename (no class in clases_calling) and in your 'readfile.py' call it by 'clases_calling.getnewfilename()'. Also, when you try to call 'imagetobit' from your current 'func_call' function it will fail because in *this* module (clases_calling.py) you have it imported as 'MainWindow.imagetobit'. I would highly recommend *not* putting this code in this module anyway, intuitively it would belong in the 'OnRead' method right after the call to your new function 'getnewfilename'. More errors to be... sigh. Here we go. In your function 'imagetobit' in readfile.py you should get an error because 'self' is not defined. You have not put self in the argument list as you did in all the other methods of MainWindow. This also means that self.imageFile1 will not be defined either, and should give you an error when trying to define it. If you adjust the imagetobit function so that it is a method of the class, we see that the imagename parameter is no longer necessary, as we can set the self.imageFile variable directly from one of the other functions. Also, I see code that looks very similar in the __init__ method of MainWindow and the function imagetobit. I suggest that you change this so that in the __init__ method you actually call self.imagetobit. To summarize: 1) Change clases_calling.py to be a single function that return the new filename as a string. 2) Change MainWindow.OnRead so that it calls this new function first (I used clases_calling.getnewfilename()), then self.imagetobit(), and finally run the rest of the commented stuff you have there (Remembering that the Image redrawing has already been done in self.imagetobit() you can delete it here) 3) Change imagetobit so that it is a method of the class MainWindow, and remove the imagename parameter 4) Change all references of self.imageFile1 to just self.imageFile. You do not need the extra. 5) Change MainWindow.__init__ so that it calls self.imagetobit() immediately after you set the variable self.imageFile And... I think that's everything. IMHO the important concept inherently missed in these two modules is that the names of the functions and variable inside are hidden behind the names. i.e. import math is used as math.sqrt, instead of just sqrt. HTH, JS ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Selecting a browser
Ricardo Aráoz wrote: > Martin Walsh wrote: > Hi Marty, thanks for your help. > I've tried your suggestions but they don't seem to work for me. In W's > system window I can do : > C:/> S:\FirefoxPortable\FirefoxPortable.exe http://www.google.com > and it will open my browser ok. But no matter what I try : > "c:/program files/mozilla firefox/firefox.exe %s &" or "c:/program > files/mozilla firefox/firefox.exe %s" as input to webbrowser.get() it > won't work. Hi Ricardo, Never would have guessed that you were using a portable browser :) But it really shouldn't matter. And by the way, the '&' has special meaning to the webbrowser.get method -- it determines whether a BackgroundBrowser or GenericBrowser object is returned. > Here's my session : > import webbrowser ff = webbrowser.get("S:\FirefoxPortable\FirefoxPortable.exe %s &") ff.open('http://www.google.com') > False I suspect (with no way to confirm at the moment) that something in the webbrowser module is confused by the backslashes. As you may know, the backslash has special meaning in python strings, used as an escape character to denote newlines (\n), tabs (\t), among others. I believe it is helpful to be aware of this when using subprocess.Popen also. And, I think you have more than one option for dealing with slashes in windows paths, but I typically just replace the backslashes with forward slashes: ff = webbrowser.get("S:/FirefoxPortable/FirefoxPortable.exe %s &") > Besides looking at the Python 2.5 documentation gave me no clues. It is > very poorly documented e.g. : > > register( name, constructor[, instance]) > Register the browser type name. Once a browser type is registered, the > get() function can return a controller for that browser type. If > instance is not provided, or is None, constructor will be called without > parameters to create an instance when needed. If instance is provided, > constructor will never be called, and may be None. > This entry point is only useful if you plan to either set the BROWSER > variable or call get with a nonempty argument matching the name of a > handler you declare. > > But it does not define what a 'constructor' is (I guess a function, but > no clue about what it's signature or functionality should be) or what an > "instance" is (but I can guess). Trouble is when you guess and things > don't work you don't have a clue if the fault lies in your 'guess' or in > your code. Note that it mentions 'the BROWSER variable' but does not say Based only on my own review of the webbrowser module source, the constructor is the '*Browser' class object [ in other words BackgroundBrowser and not BackgroundBrowser() ], presumably it should be a subclass of webbrowser.GenericBrowser. And instance is what you would think, an instance of a '*Browser' class. > what it is, what it's value should be, nor any clue about it's use. > Probably I lack knowledge in the subject, but hey! the whole purpose of > this module is to be able to call the browser WITHOUT any knowledge of > the subject. > I guess I'll have to look at the code when I have a couple of free hours. I would highly recommend it. It's straight forward, and very readable. A helpful tip, perhaps: one of my favorite features of ipython, allows fairly trivial access to a module's python source (not that it's difficult by other means, really): In [1]: import webbrowser In [2]: webbrowser?? A single question mark prints the doc string if available, where the ?? pages the source. On linux, not sure about windows, I can move around and search for text with all the same familiar keyboard commands (less style). > I'd rather go with the 'webbrowser' module than the subprocess.Popen > option, as it 'should' abstract me from browser management. Anyway if I I think that's the intent of the module, and a worthwhile pursuit. But, IMHO you may find it's more work, and less flexible, than keeping track of the browser paths yourself and calling subprocess.Popen -- on Windows at least. YMMV. And it is certainly possible that you'll discover some feature of the webbrowser module that I've overlooked. So, I hope you'll report back to the list with your progress. Good luck! Marty > can't advance through webbrowser I'll give your examples a try. > Thanks a lot for your help. > > Ricardo > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Selecting a browser
Ricardo Aráoz wrote: import webbrowser ff = webbrowser.get("S:\FirefoxPortable\FirefoxPortable.exe %s &") ff.open('http://www.google.com') > False Beware of backslashes in file paths - backslash introduces a character escape in Python strings. You can fix by any of - use \\ instead of \ - use / instead of \ (it works fine) - use raw strings (prefix with r) e.g. r"S:\FirefoxPortable\FirefoxPortable.exe %s &" Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] help
Andrew Critchley wrote: > I recently downloaded the newer version of python, the 2.5.1 one, and > when ever i try to make an input what ever i type into the brackets > appears on the next line and when i try to add the next line it > carries on from the input,This is what happens: > > I type this down: > > # Area calculation program > > >>>print “Welcome to the Area calculation program” > >>>print “–” > >>>print > > >>># Print out the menu: > >>>print “Please select a shape:” > >>>print “1 Rectangle” > >>>print “2 Circle” > > >>># Get the user’s choice: > shape = input(“>30 “) > >30 (and then this line appears) > (here i should type "# Calculate the area:" but it carries on from the > above line and when i press enter i encunter an error and it all goes > wrong) > please help me with this problem. You are running the interpreter. Each line is executed after you enter it. You should be typing your program in an editor or IDE > such as IDLE. > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Selecting a browser
Kent Johnson wrote: > Ricardo Aráoz wrote: > import webbrowser > ff = webbrowser.get("S:\FirefoxPortable\FirefoxPortable.exe %s &") > ff.open('http://www.google.com') >> False > > Beware of backslashes in file paths - backslash introduces a character > escape in Python strings. You can fix by any of > - use \\ instead of \ > - use / instead of \ (it works fine) > - use raw strings (prefix with r) e.g. > r"S:\FirefoxPortable\FirefoxPortable.exe %s &" > Thanks Kent, that was certainly the problem. So I went through it just to hit another wall, when issuing the open method : >>> ff.open('http://www.google.com') Traceback (most recent call last): File "", line 1, in File "E:\Python25\lib\webbrowser.py", line 168, in open p = subprocess.Popen(cmdline, close_fds=True) File "E:\Python25\lib\subprocess.py", line 551, in __init__ raise ValueError("close_fds is not supported on Windows " ValueError: close_fds is not supported on Windows platforms No easy way, I'll have to check the module's code. Or go Marty's way (that's popen). Thanks ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Selecting a browser
Martin Walsh wrote: > Ricardo Aráoz wrote: >> Martin Walsh wrote: >> Hi Marty, thanks for your help. >> I've tried your suggestions but they don't seem to work for me. In W's >> system window I can do : >> C:/> S:\FirefoxPortable\FirefoxPortable.exe http://www.google.com >> and it will open my browser ok. But no matter what I try : >> "c:/program files/mozilla firefox/firefox.exe %s &" or "c:/program >> files/mozilla firefox/firefox.exe %s" as input to webbrowser.get() it >> won't work. > > Hi Ricardo, > > Never would have guessed that you were using a portable browser :) But > it really shouldn't matter. And by the way, the '&' has special meaning > to the webbrowser.get method -- it determines whether a > BackgroundBrowser or GenericBrowser object is returned. LOL, another demerit to documentation. I not only use a portable browser, it's inside a TrueCrypt volume in my pen drive. That means I'm not restrained to my company's choices on browsers or their settings, and I get 'some' degree of privacy. > >> Here's my session : >> > import webbrowser > ff = webbrowser.get("S:\FirefoxPortable\FirefoxPortable.exe %s &") > ff.open('http://www.google.com') >> False > > I suspect (with no way to confirm at the moment) that something in the > webbrowser module is confused by the backslashes. As you may know, the > backslash has special meaning in python strings, used as an escape > character to denote newlines (\n), tabs (\t), among others. I believe it > is helpful to be aware of this when using subprocess.Popen also. And, I > think you have more than one option for dealing with slashes in windows > paths, but I typically just replace the backslashes with forward slashes: > > ff = webbrowser.get("S:/FirefoxPortable/FirefoxPortable.exe %s &") > That did it, but as I told Kent : ff.open('http://www.google.com') Traceback (most recent call last): File "", line 1, in File "E:\Python25\lib\webbrowser.py", line 168, in open p = subprocess.Popen(cmdline, close_fds=True) File "E:\Python25\lib\subprocess.py", line 551, in __init__ raise ValueError("close_fds is not supported on Windows " ValueError: close_fds is not supported on Windows platforms Don't worry, I see I'll have to look into the module's code or go the popen() way. I'll let you know. Again, thanks a lot for your help. Ricardo ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Selecting a browser
Ricardo Aráoz ha scritto: >> ff = webbrowser.get("S:/FirefoxPortable/FirefoxPortable.exe %s &") > That did it, but as I told Kent : > > ff.open('http://www.google.com') > Traceback (most recent call last): > File "", line 1, in > File "E:\Python25\lib\webbrowser.py", line 168, in open > p = subprocess.Popen(cmdline, close_fds=True) > File "E:\Python25\lib\subprocess.py", line 551, in __init__ > raise ValueError("close_fds is not supported on Windows " > ValueError: close_fds is not supported on Windows platforms I think the problem is in '&' at the end of the command line. The '&' is used on Linux/Unix system to start processes in a independent thread. Remove it and it works! Simone Chiacchiera con i tuoi amici in tempo reale! http://it.yahoo.com/mail_it/foot/*http://it.messenger.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor