[Tutor] regex help
I have a string: 'a b c h' I would like a regex to recursively match all alpha letters that are between . That is, I would like the following list of matches: ['d', 'e', 'f', 'i', 'j'] I do not want the 'g' or the 'k' matched. I have figured out how to do this in a multiple-step process, but I would like to do it in one step using only one regex (if possible). My multiple step process is first to use the regex '(?<=H )[a-z][^H]+(?!H)' with re.findall() in order to find two strings ['d e f ', 'i j '] I can then use another regex to extract the letters out of the strings. But, as I said above I would prefer to do this in one swoop. Another example: 'a b c' There should be no matches. Last example: 'a b c' There should be one match: ['d'] (For background, although it's probably irrelevant, the string is a possible representation of a syllable (a, b, c, etc.) to tone (H) mapping in tonal languages.) If anyone has ideas, then I would greatly appreciate it. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Exercises for Classes and OOP in Python
Hello, I am looking for a good material that would provide exercises (and possibly solutions to demo exercises) that illustrates the Object Oriented Programming constructs in Python. Can pointers? TIA, Senthil ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] calling user defined function
"roberto" wrote i can define a function using the text editor provided by IDLE 3.0; then i'd like to call this function from the python prompt but when i try to do it, python warns me that function doesn't exist of course if i define the function directly using the >>> prompt, after that everything is fine You need to save the file containing the function in a folder in the Python search patyh. tHis is defined in sys.path: import sys print sys.path Saving your file in any folder there will allow python to import the file as a module. Thus if you save it in C:\MyProjects\Python\myFunction.py and C:\MyProjects\Python is in your sys.path You can then import your file with import myFunction # notice no .py And call your function foo() with myFunction.foo() You can add folders to sys.path either in a startup script or using the PYTHONPATH environment variable. Make sure its PYTHONPATH you create or modify not PATH, they are very different! HTH -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] calling user defined function
On Sun, Feb 22, 2009 at 4:21 PM, roberto wrote: > hello > i have a question which i didn't solved yet: > i can define a function using the text editor provided by IDLE 3.0; > then i'd like to call this function from the python prompt > > but when i try to do it, python warns me that function doesn't exist > of course if i define the function directly using the >>> prompt, > after that everything is fine > > may you tell me where i have to save the file that defines the > function is order to use it later ? The simplest way is to save the file in your working directory, then import as Bob showed you. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] calling user defined function
Le Sun, 22 Feb 2009 22:21:22 +0100, roberto s'exprima ainsi: > hello > i have a question which i didn't solved yet: > i can define a function using the text editor provided by IDLE 3.0; > then i'd like to call this function from the python prompt > > but when i try to do it, python warns me that function doesn't exist > of course if i define the function directly using the >>> prompt, > after that everything is fine > > may you tell me where i have to save the file that defines the > function is order to use it later ? > is it a problem of path ? I guess what you mean is how to run your program? If you write it inside the editor (as opposed to the interactive window where you get the prompt), then all you need is save (where ever you like it) and run (menu or F5). The program's output, if any, will then happen inside the interactive window. You can also "run" a program or module by importing it from inside the interactive window, using >>> import filenamewithoutdotpy Further runs/imports during the same session must however be expressed with >>> reload(filenamewithoutdotpy) Denis -- la vita e estrany ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] calling user defined function
roberto wrote: hello i have a question which i didn't solved yet: i can define a function using the text editor provided by IDLE 3.0; then i'd like to call this function from the python prompt but when i try to do it, python warns me that function doesn't exist of course if i define the function directly using the >>> prompt, after that everything is fine may you tell me where i have to save the file that defines the function is order to use it later ? is it a problem of path ? Let's say you saved the file as foo.py. Then: >>> import foo >>> foo.afunction() -- Bob Gailer Chapel Hill NC 919-636-4239 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] extracting a column from many files
For example, if you have input files: file1: 1a1 1b1 1c1 1d1 1e1 1f1 2a1 2b1 2c1 2d1 2e1 2f1 3a1 3b1 3c1 3d1 3e1 3f1 file2: 1a2 1b2 1c2 1d2 1e2 1f2 2a2 2b2 2c2 2d2 2e2 2f2 3a2 3b2 3c2 3d2 3e2 3f2 How do you want the output files to look like? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] calling user defined function
hello i have a question which i didn't solved yet: i can define a function using the text editor provided by IDLE 3.0; then i'd like to call this function from the python prompt but when i try to do it, python warns me that function doesn't exist of course if i define the function directly using the >>> prompt, after that everything is fine may you tell me where i have to save the file that defines the function is order to use it later ? is it a problem of path ? my version of python is 3.0, OS windows xp thank you very much in advance -- roberto OS: GNU/Linux Debian Kubuntu, Edubuntu ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] extracting a column from many files
On Thu, Feb 19, 2009 at 2:41 AM, Bala subramanian wrote: > Dear friends, > > I want to extract certain 6 different columns from a many files and write it > to 6 separate output files. I took some help from the following link > > http://mail.python.org/pipermail/tutor/2004-November/033475.html > > to write one column from many input files to a particular output file. Let me see if I understand what you want to do. You have file1.txt, file2.txt, file3.txt ... and you want to read n columns from those files? It gets confusing. How many columns do you want to read from each file? How many columns does each output file have? Also, it would be very helpful if you give us the format of the input and output files. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Looking for ConfigObj Documentation
> Under Start there's a ? icon that says Help and Support. Minimal info. Yes, although by exploring the links and using the Microsoft Knowledgebase panel on the left you do get more than I remembered. I just think the DOS HELP command is easier to use. However I did find a good overview on Technet: http://technet.microsoft.com/en-us/library/bb490954.aspx Which has a lot of other stuff on cmd.exe too. > It seems to me that the Command Prompt window is important enough > in the use of Python to warrant a full page somewhere to its applicability. I might try to do that sometime. But its not really Python specific, if you are doing any serious programming or admin work on a PC you really should be familiar with the cmd window, its often the fastest and easiest way to do stuff. And learning the little tricks and settings that make it more productive is definitely worthwhile. Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Simple CGI script and Apache configuration
Hello all, I'll try to give as much detail as I can, but this is a somewhat vague problem. I have a very simple script that I would like to implement as a CGI script, just so I can hit a URL and get some output. However, after following a number of tutorials, I am still seeing some very odd results. I am almost sure it's in my Apache configuration, but I figured a few people on this list would likely know what the minimal related Apache config should be. (The Apache docs are pretty daunting...) Local version wise, I am on Ubuntu 8.10, with Apache 2.2.9 and Python 2.5.2. I have libapache2-mod-python installed. Apache config is out of the box, along with: ScriptAlias /cgi-bin/ "/var/www/cgi-bin/" In /var/www/cgi-bin, I have hello.py: #!/usr/bin/python import cgitb cgitb.enable() print "Content-type: text/html" print print "" print "Hello!" print "" Reload, hit http://localhost/cgi-bin/hello.py in a browser, I get centered text just fine. Now I want to do this same process on my remote webserver. On there, I am on Ubuntu 7.10, with Apache 2.2.4 and Python 2.5.1. I add: ScriptAlias /python/ "/var/www/samuelhuckins.com/python" Reload, hit http://samuelhuckins.com/python/hello.py, and I get a 404? The perms and ownership on the file is the same as in other directories. Do I need to add some sort of handler, with mod_python.publisher? I think I am just missing one of the basics of this whole process. Thanks for any assistance, Sam ___ Samuel Huckins Homepage - http://samuelhuckins.com Tech blog - http://dancingpenguinsoflight.com/ Photos - http://www.flickr.com/photos/samuelhuckins/ AIM - samushack | Gtalk - samushack | Skype - shuckins ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Looking for ConfigObj Documentation
Title: Signature.html Under Start there's a ? icon that says Help and Support. Minimal info. It seems to me that the Command Prompt window is important enough in the use of Python to warrant a full page somewhere to its applicability. Well, if not, then I'll make do with what I've seen here. Alan Gauld wrote: "Wayne Watson" wrote tried XP's Help on command prompts. Not much there. Is there another source? When you say XPs help do you mean the GUI help tool? There isn't much in there. For DOS things use the DOS help tool. Type HELP CMD at the DOS prompt. Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time) "Nature, to be commanded, must be obeyed." -- Sir Francis Bacon Web Page:___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Looking for ConfigObj Documentation
"Wayne Watson" wrote tried XP's Help on command prompts. Not much there. Is there another source? When you say XPs help do you mean the GUI help tool? There isn't much in there. For DOS things use the DOS help tool. Type HELP CMD at the DOS prompt. Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] cgi script to start another process in background
Hi, I am trying to write a python cgi script, that invokes another process and exists. Using the subprocess documentation on NO_WAIT, I am not having much success: pid = os.spawnlp(os.P_NOWAIT, "/bin/mycmd", "mycmd", "myarg") ==> pid = Popen(["/bin/mycmd", "myarg"]).pid The script seems to wait for the new process to exit before returning to the user. I tried doing the double-fork approach discussed here: http://code.activestate.com/recipes/66012/ I am not having much luck. Any ideas on how to accomplish this appreciated. thanks, Ravi. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor