Re: [Tutor] Web programming advice
Things you need to know. In order * HTML * Javascript * CGI Webscripting, this teaches you the difference between GET and POST, with this you can make simple things, like a page view counter for example, or a simple game of hangman. * Web framework or Templating language, python is not well suited to just spraying code inside markup. On Fri, Sep 19, 2008 at 11:38 AM, dorje tarap [EMAIL PROTECTED]wrote: Hi All, I would really like to learn about using python for creating a website from scratch to allow me to learn about web programming and python. I have zero experience of web programming, and some limited exposure to python. Can someone recommend a book or resource that will introduce me to web programming. Thanks ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] ways to sync databases with Python and SQLite?
One way to work around this and still use SQLight is to put the database on a shared drive. SQLight does table locking, or is it file locking. Anyways conflicts will be very minimal to non-existant with only two clients as most operations will complete in microseconds. The SQLight website even says this is a fine practice. However synchronizing two separeatly running databases is a very hard task, and is very very easy to get wrong. However if all that one does is read and does no updates or deletes then you could just copy the database over to the 'client' user. On Tue, Sep 9, 2008 at 6:56 PM, Che M [EMAIL PROTECTED] wrote: Hi list, I have been trying to create a small desktop application with Python that uses a small SQLite database. Recently I've got use of a 2nd computer (for my job) and have thought now about using the app on that one as well. I'd like to get ideas about how I could extend the application so that the databases on each computer could be kept synchronized (not sure that is the right term here); that is, each new change on either computer would be updated on the other computer(s), given a bit of help from the user. I know that, for example, the Chandler PIM has a hub that allows sync'ing across multiple computers (though I was surprised to see it is a 8 step process for the user: http://chandlerproject.org/Projects/GetStarted#Sync%20Chandler%20Desktop%20across%20Mul) (I realize a good way to do all of this is entirely as a web service, but that is beyond my abilities, and I am trying to just complete a desktop app before learning much of that) So, if anyone has ideas on ways to do this with Python and Sqlite that are: - fairly simple (I'm not a real programmer) - not laborious for the user to do (so that they actually keep the two dbs in sync) I'd love to hear about it. Thanks, Che -- Stay up to date on your PC, the Web, and your mobile phone with Windows Live. See Nowhttp://clk.atdmt.com/MRT/go/msnnkwxp1020093185mrt/direct/01/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Is there python editor or plugin for a python editor for curly brackets around code blocks?
Oh, I forgot there's another way to add braces if it_is_way_cool: #{ print 'coolness' #} On Wed, Aug 13, 2008 at 11:06 PM, xbmuncher [EMAIL PROTECTED] wrote: I'll check out your links. But in response to some of the things said: I'm a fan of indentation, a replacement of indentation with curly braces is not what I was aiming for. If I could have it my way, I'd have indentation and curly braces. I don't want to change official python syntax either.. I just want to be able to easily do it myself. The big problem I had that I didn't explain well enough when I said visually is that it is visually hard to tell when code blocks end when other code blocks and statements begin immediately after them. With curly braces you can easily visualize when looking at a lot of code where the code block ends. The best thing you can do in python currently is to put an empty line in between the last line of a code block and the following code, so you can better visualize the end of the code block. On Wed, Aug 13, 2008 at 4:23 AM, Chris Fuller [EMAIL PROTECTED] wrote: Some clarifications w.r.t. indentation and Python: http://www.secnetix.de/olli/Python/block_indentation.hawk It's just a joke, really: http://timhatch.com/projects/pybraces/ Turnabout is fair play! http://blog.micropledge.com/2007/09/nobraces/ Also, pindent.py in the Tools/scripts directory of your Python distribution will produce correctly indented scripts if the blocks are designated with a #end line. But seriously, you don't want to go creating a separate class of source file. It'll be harder for you and the other programmers to context switch when working with code that uses the standard style, will confuse others who won't know what to do with your code, adds overhead to the compiling, will break when somebody tries to run it under the standard environment, could clutter up your development directories, depending on the implementation, etc. Here's a thread from 1999 on the Python mailing list that discusses the issue: http://mail.python.org/pipermail/python-list/1999-June/004450.html There's another script towards the end that might even do what you want, but you might want to read what they have to say first :) Cheers ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] What has Editor X got that PyWin32 hasn't?
Well I would imagine that many of the programmers here use emacs or vim. I use vim, however I've used komodo for python and I liked it a lot. However if you are going to program a great deal (I don't' know what your intentions are) then I recomend taking the 20-40 hour it takes to learn emacs or vim. These editors allow you to shovel around code like your a ditch digger, with cybernetic implants. Vim has code completion and it's very easy to use your keyboard to switch to specific tabs, instead of ctrl-tab,tab,tab,tab,tab,tab. It does have command completion though it requires you to tell it how to do so. Syntax highlighting and many other must haves for me. There is one thing that VIM and emacs have for them that many of the more GUI editors lack. That is terminal support that is equal to the GUI version. I do a lot of system administration just to get my programming tasks done and I often do not have physical access to the machine so I need to do it remotely. Which is a huge win for me. On Tue, Aug 12, 2008 at 4:09 PM, Steve Willoughby [EMAIL PROTECTED] wrote: Jaggo wrote: Why do you use your editor rather than using Pywin? What feature has editor X got that PyWin hasn't? (That is, other than My editor runs on unix / linux; while that does count for something it is rather irrelevant to my current situation.) I use a different editor (in my case vim) because it has a lot of advanced editing features (regular expression searching and replacing, filtering ranges of text through commands, and a list of scores of other things) that don't exist in the simpler editors built into most IDEs like Pywin or IDLE. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] I need a Python mentor
Actually the way this list works is there is no one person who will do this. However if you pose a specific question I'm sure you will get several helpful people will respond. Like this. What book did you read and what topics did it cover? From there someone perhaps even myself will be able to make up something nice for you to program. Then when you have problems with the program come back and ask questions. Since you already programmed in PHP I don't think you'll have too much trouble picking up python. On Fri, Aug 8, 2008 at 5:22 PM, A. Joseph [EMAIL PROTECTED] wrote: Hello everybody, i`m new to this list. I was programming in PHP before, of recent I started learning python. I need someone who can be giving me some assignment based on the chapter I read in the book, and the person will sometime review my code and tell me if it`s well structured. Thanks- ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Communication between threads
This is a great suggestion. I too learned how to do threading in python from reading code. For me I read the btdownloadheadless.py code. Which comes as part of the standard bittorrent client in linux. On Thu, Jul 31, 2008 at 7:11 AM, Monika Jisswel [EMAIL PROTECTED] wrote: I'm looking for some thoughts on how two separate threads can communicate in Python You will probably get out of your doubts by reading about the SocketServer module and SocketServer.ThreadingTCPServer class. Once your get a server up running you can run parallel threads, from there you can build a global dictionary use it to share data between you threads. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] confusing HTTP error while using urlopen
Well I can confirm this behavior. I tried changing the user-agent thinking there might be some filtering based on that but no go. Still HTTP 400 error. WGET works just fine though On Fri, Jul 18, 2008 at 4:31 PM, asdg asdg [EMAIL PROTECTED] wrote: I'll skip the introduction and go right to the question cause it's as simple as it's confusing for me. Why does urllib2.urlopen(http://www.anuntul.ro;) return HTTPError: HTTP Error 400: Bad Request, while the site opens with no problems in any regular browser. Thank you in advance for answering :) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Trying to extract the last line of a text file
On 10/19/06, Chris Hengge [EMAIL PROTECTED] wrote: I'd personally do something like this. file = open(myfile, 'r')fileContents = file.readlines() # read the entire document into memory for speed.file.close()print fileContents[-1] # This is the last line. This works as wellfile('filename.txt').readlines()[-1]Some will say that this is no good because the file is still open. However I've been told that when the object is cleaned the file is closed so it should be fine. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] simple question about numeric types
I think isinstance() is probably the best way to do this. I however always do type(x)==TestType: where TestType is a string that is returned from type() or not what ever the case. On 5/8/06, Emanuele Rocca [EMAIL PROTECTED] wrote: Hello list, I've got a question partially related to this thread. * Gregor Lingl [EMAIL PROTECTED], [2006-05-03 0:24 +0200]: v=some numeric value if isinstance(v, int) or isinstance(v, float): block I wonder which is the recommended way to check the type of a value. In other words, what should I choose between: isinstance(v, int) type(v) is int v.__class__ is int There's simply more than one way to do it or some of them are discouraged? I've been told on #python that .__class__ is probably the worst one, but without precise motivation, just as a personal opinion. ciao, ema -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.3 (GNU/Linux) iD8DBQFEX4X7C6DuA+rxm2ARAio8AJ9VWrIjlXL5bk43o0LwS1ZwPE3gZACdGTWI eIRPzxfs6KRpYc3bF2W4RwU= =Tmcs -END PGP SIGNATURE- ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] web intefaces?
While everything that Alan Guald said is true, there are a couple of options for you. Provided you know HTML (you must), you could generate html pragmatically but, knowledge of html is still mandatory. Your options are, basically http://www.cherrypy.org Which is an app server that should be fairly easy to package up with, say py2exe. Another option, with CGI (pretty easy) is found in the standard library. http://docs.python.org/lib/module-CGIHTTPServer.html If you do this as a personal app I would make sure to use an alternate port number like 11224, or something. HTH Best of Luck. On 5/6/06, Alfonso [EMAIL PROTECTED] wrote: I would like to experiment with web interfaces and python. After some googling, I'm quite confused, does somebody know of a good link about this topic / what do you think that is the best software option to design web user intefaces with python? I mean web interfaces for common programms (so it's not important to me to have a very robust web server), the web server should run in the machine of the user of the programm.And it should be easy installed, as bundle, when I distribute the programm. Thank very much for your help. __ LLama Gratis a cualquier PC del Mundo. Llamadas a fijos y móviles desde 1 céntimo por minuto. http://es.voice.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Books
I have learend a great deal of python, and I have never bought a book. All the information one really needs is available freely on the internet. As long as you understand the basic data types you should be able to piece together what you need from the internet. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Bitten by lexical closures
Are you just trying to make a continuation? On 5/3/06, Igor [EMAIL PROTECTED] wrote: Hi. And I thought I understood python pretty well. Until I got hit by this: def f(x): ... print x cb = [lambda :f(what) for what in 1234] for c in cb:c() 4 4 4 4 And even this works what = foo for c in cb:c() foo foo foo foo I expected the output to be 1 2 3 4. Now I understand the cookbook recipe for currying: def curry(func, *args, **kwds): def callit(*moreargs, **morekwds): kw = kwds.copy() kw.update(morekwds) return func(*(args+moreargs), **kw) return callit cb = [curry(f,what) for what in 1234] gives the right functions. Regards, Igor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] database app
Well when working with M$ db's you should use odbc. http://www.egenix.com/files/python/mxODBC.html nephish wrote: Hey there, i have used the cgi module and dig it. heres the deal, my employer wants me to build a dynamic website that will access a database and display customer information on web. ok, easy enough. heres the trick. the database is MS Access. - ick. what could i do to manipulate data in an access database ? can it be done ? all the research i have done just points me to sql, sqlite, etc... i wouldnt mind if i can find a way to push everything from access to another kind of database, but i dont know where to start. any ideas? -thanks ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor Yahoo! Sports Rekindle the Rivalries. Sign up for Fantasy Football http://football.fantasysports.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Checking if value exist in a '2D array'
Kent Johnson wrote: Olli Rajala wrote: Hi again, I have a '2D array', I mean a list inside a list ([[][],[][],...]) and would need to check if the value exists in it. Of course I could do a for loop, but that just seem to be a little overkill, so is there any other way to do it? I have to check the first cell of every insider list. With Python 2.4: l= [ [1], [2,3], [4,5], [6]] 2 in (i[0] for i in l) True 3 in (i[0] for i in l) False with Python 2.3 use [i[0] for i in l] instead which is a little less efficient. The second case you show should be true because I believe that's what he asked for. Here is I believe the correct way to do this. l= [ [1], [2,3], [4,5], [6]] def isin(test,alist): ... return bool([x for x in alist if test in x]) ... isin(2,l) True isin(3,l) True isin(10,l) False def isin2(test,alist): ... for x in alist: ... if test in x: ... return True ... return False isin2(2,l) True isin2(10,l) False __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] test
How about this. from random import choice alist=[choice(range(100)) for x in range(1000)] #just making a list to look at pretend this is a file counter={} for item in alist: ... if item in counter.keys(): ... counter[item]+=1 ... else: ... counter[item]=1 ... counter {0: 9, 1: 9, 2: 9, 3: 14, 4: 15, 5: 15, 6: 13, 7: 5, 8: 11, 9: 12, 10: 9, 11: 12, 12: 13, 13: 8, 14: 5, 15: 12, 16: 14, 17: 9, 18: 11, 19: 8, 20: 6, 21: 13, 22: 11, 23: 10, 24: 8, 25: 15, 26: 19, 27: 11, 28: 13, 29: 13, 30: 12, 31: 18, 32: 10, 33: 5, 34: 9, 35: 5, 36: 9, 37: 12, 38: 8, 39: 11, 40: 8, 41: 12, 42: 6, 43: 13, 44: 11, 45: 8, 46: 8, 47: 6, 48: 9, 49: 6, 50: 5, 51: 11, 52: 11, 53: 12, 54: 15, 55: 15, 56: 10, 57: 12, 58: 13, 59: 6, 60: 6, 61: 7, 62: 8, 63: 13, 64: 14, 65: 7, 66: 7, 67: 12, 68: 5, 69: 10, 70: 8, 71: 7, 72: 12, 73: 12, 74: 6, 75: 13, 76: 12, 77: 13, 78: 9, 79: 5, 80: 13, 81: 14, 82: 4, 83: 6, 84: 8, 85: 12, 86: 8, 87: 10, 88: 10, 89: 7, 90: 7, 91: 9, 92: 12, 93: 14, 94: 8, 95: 7, 96: 10, 97: 11, 98: 8, 99: 8} Asif Iqbal wrote: Hi All I have a very simple problem and I am looking for the simplest solution. I have a list of elements in a file. I like to find the total occurance of each element in the list like this 10 string1 7 string2 1 string3 from a list which has only string1,string2 and string3 like this string1 .. string2 ... string1 .. string3 ... ... I have a list of 3 lines and I think I have only 615 unique elements. So I like the script not to take too much memory of the system. I will be running it on Solaris 8 Thanks a lot Yahoo! Sports Rekindle the Rivalries. Sign up for Fantasy Football http://football.fantasysports.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] test
Asif Iqbal wrote: On Fri, Jun 17, 2005 at 07:41:17AM, Chad Crabtree wrote: How about this. from random import choice alist=[choice(range(100)) for x in range(1000)] #just making a How do I do this in python? alist /tmp/logfile The logfile has the list of entries. ok sorry filehandle=open('/tmp/logfile','r').readlines() Look here http://docs.python.org/lib/built-in-funcs.html#built-in-funcs and http://docs.python.org/lib/bltin-file-objects.html __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Py2exe (Joseph Q.)
The symptoms you explain mean you don't have py2exe installed correctly. Try uninstalling it and reinstalling it. Joseph Quigley wrote: Joseph Q. (Uspantan, Guatemala) Using Python 2.4 I downloaded py2exe and can't get it to make exe's of my python files. There are a list of instructions: # A very simple setup script to create 2 executables. # # hello.py is a simple hello, world type program, which alse allows # to explore the environment in which the script runs. # # test_wx.py is a simple wxPython program, it will be converted into a # console-less program. # # If you don't have wxPython installed, you should comment out the # windows = [test_wx.py] # line below. # # # Run the build process by entering 'setup.py py2exe' or # 'python setup.py py2exe' in a console prompt. # # If everything works well, you should find a subdirectory named 'dist' # containing some files, among them hello.exe and test_wx.exe. from distutils.core import setup import py2exe setup( # The first three parameters are not required, if at least a # 'version' is given, then a versioninfo resource is built from # them and added to the executables. version = 0.5.0, description = py2exe sample script, name = py2exe samples, # targets to build # windows = [test_wx.py], console = [hello.py], ) What does it mean by the 'console prompt'? I tried Command Prompt (Windows XP) but I get errors when I type 'setup.py py2exe' or 'python setup.py py2exe'. I also don't get anything when I run the setup.py in IDLE (or the Python command line). In fact I get an error: Traceback (most recent call last): File C:\Python24\Lib\site-packages\py2exe\samples\simple\setup.py, line 22, in ? import py2exe ImportError: No module named py2exe If you have used or are using py2exe, /please/ tell me what I'm doing wrong! Thanks, Joseph Q. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor __ Do you Yahoo!? Yahoo! Small Business - Try our new resources site! http://smallbusiness.yahoo.com/resources/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] A Pythonic LinkedList Implementation
I'm at a loss as to why this is helpful. How and why would one use this instead of a regular list? I know what linked lists are and why they would be useful in C++ or C or any other but not python. Orri Ganel wrote: Hello all, I've been working on making a complete pythonic LinkedList implementation, as per the specifications of Java's LinkedList and Python's list. The full code may be found at http://rafb.net/paste/results/JKhsQn59.html. Once the link expires, please feel free to email me for the code. Any suggestions and comments are welcome. As far as I can tell, the only possible improvement to be made is adding comments. Thanks in advance, Orri __ Do you Yahoo!? Read only the mail you want - Yahoo! Mail SpamGuard. http://promotions.yahoo.com/new_mail ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Are you allowed to shoot camels? [kinda OT]
Alan Gauld wrote: ie No lambda used at all. I wish Python had real lambdas! If python had real lambda's then it would be lisp or schema. __ Do you Yahoo!? Yahoo! Mail - now with 250MB free storage. Learn more. http://info.mail.yahoo.com/mail_250 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Are you allowed to shoot camels? [kinda OT]
Jacob S. wrote: aFuncList=[] def x(): print one aFuncList.append(x) def x(): print two aFuncList.append(x) def x(): print three aFuncList.append(x) for item in aFuncList: item() Okay, for this problem (it can be altered otherwise) def makefunct(stri): def x(): print stri return x aFuncList = [makefunct('one'),makefunct('two'),makefunct('three')] for item in aFuncList: item() It's shorter, it works and it looks cool. Thanks to Jeff Shannon for the backbone of this example. My intent in showing the above code was not to really print one two three, but to show that a function doesn't care what it's called. __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Re: This Deletes All my Files
Thank you all for answering my question. I thought it would be some misunderstanding on my part. The example Andrei made was very telling. Andrei wrote: s = d:/tests/test.txt class dummyfile(object): ... def open(self, *args): ... print dummyfile.open:, args ... def write(self, *args): ... print dummyfile.write:, args ... def read(self, *args): ... print dummyfile.read:, args ... return def dummyopen(filename, type): ... print dummyopen:, filename, type ... d = dummyfile() ... d.open(filename, type) ... return d dummyopen(s, 'w').write(dummyopen(s, 'r').read()) dummyopen: d:/tests/test.txt w dummyfile.open: ('d:/tests/test.txt', 'w') --- first open for writing dummyopen: d:/tests/test.txt r dummyfile.open: ('d:/tests/test.txt', 'r') --- then for reading dummyfile.read: () dummyfile.write: ('',) spend 5 hours RTFM. I got it to work by breaking it up to several statements, but I would like to know. And that's the way you *should* write it - code like this doesn't deserve to work anyway :). Yours, Andrei ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor __ Do you Yahoo!? The all-new My Yahoo! - Get yours free! http://my.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Are you allowed to shoot camels? [kinda OT]
Max Noel wrote: According to the Jargon file, this one is called Whitesmiths style. I tend to use Allman style myself, but given the code completion, spellchecking, etc. in modern IDEs, I suspect it's become more a question of personal preference than anything else. A bit like if(foo) versus if (foo), and whether or not to use braces for single-line blocks. (the latter issue being why I think The Whitespace Thing is an instance of Best Thing Ever(TM)) Bracing single line expressions is something I constantly agonize over. I'm always thinking may as well brace it because I may want to add more to this if clause. That's one of the reasons I like python is because it's relatively painless to make sure that your blocks are closed properly, especially when you aren't using a decent IDE. __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] files in a directory
Well in the same vein as what the others put out there I made a verbose 'ls *.ext' so that you can see how to do it in one go. I figured this would give you enough of an example. You can hard code these things into your program. I used a construct similar to this to create an instant html photo gallery. #!/usr/bin/env python import sys,os print sys.argv if len(sys.argv)3: print Please type dir.py dir=directory ext=extension Example dir.py dir=. ext=html To list all the html files in the current directory sys.exit() dir=sys.argv[1] ext=sys.argv[2] dir=dir.split('=') ext=ext.split('=') if not (dir[0].lower()=='dir' and ext[0].lower()=='ext'): print Invalide Command line systax dir.py dir=directory ext=extension sys.exit() #now we can get started dirlist=os.listdir(dir[1]) dirlist=[tuple(x.split('.')) for x in dirlist] for x in dirlist: if x[-1]==ext[1]: print '.'.join(x) kumar s wrote: f2.close() The problem with this approach is that, i have to give on file per a run. I have 50 files to pare and i want to do that in one GO. I kepy those 50 files in one directory. Can any one suggest an approach to automate this process. I tried to use f1 = stdin(...) it did not work. i dont know , possible is that i am using incorrect syntax. Any suggestions. Thank you. __ Do you Yahoo!? Yahoo! Mail - Find what you need with new enhanced search. http://info.mail.yahoo.com/mail_250 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Syntax Check
Does anyone happen to know how to turn of the syntax checking in python? I've been working on a module driven preprocessor but I'd like to not have to use comment strings. __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Syntax Check
Well I don't think that it would really require that. I could just define macro's in a module and just do it like so import macro import defined_macros as m macro.expand(m.with(),m.assert()) I just thought it would be best to have definitions at the head of a script, or at least to have the option. Jeff Shannon wrote: Perhaps you could turn things around, and make your macro preprocessor into an import hook? I.E., you'd use it like -- import macro module = macro.import(module_with_macros[, macro_list]) module.do_stuff() Not sure if you'd need to have a list of macros in the module to be imported, or not. Perhaps the macro module would hold a list of currently active macros, instead... In any case, this (I think) gives you a chance to interrupt the import process and modify the target module before the Python parser gets it, which should enable you to avoid the SyntaxError problems. (Of course, I've never messed around with hooking __import__(), so I could just be talking out of my ...) __ Do you Yahoo!? Yahoo! Mail - now with 250MB free storage. Learn more. http://info.mail.yahoo.com/mail_250 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] New to Python
I too once had trouble remembering (and finding) the name of this library so here it is. http://www.tizmoi.net/watsup/intro.html I have not used it but the documentation by example, seemed to me to be approachable. Tony Meyer wrote: There's a Python library for controlling Windows in this sort of way (simulating mouse clicks and so on), although the name escapes me at the moment. However, are you positive that you can't control it properly? Check to see if it has a COM interface (you can use PythonWin to do that), and use that if possible. =Tony.Meyer __ Do you Yahoo!? The all-new My Yahoo! - What will yours do? http://my.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Preffered way to search posix filesystem
Try the os module. I think this should probably get you there. http://docs.python.org/lib/module-os.html Miles Stevenson wrote: I would like to search filesystem structures using globs on Posix systems from within Python. I don't see an obvious method to do this with in the standard modules. What is the preferred way of doing this? Should I just use the find command or is there a good module out there for searching? Thanks. __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Unique Items in Lists
Ok. I think I understand and I happen to be up at 1:30 my time so here is the solution as I understand the problem. This is a very common problem and has a fairly easy solution. You can then take adict.keys() which returns a list of unique elements. Good Luck import random l=[random.randrange(1,20) for x in range(100)] l [7, 18, 17, 17, 6, 11, 14, 9, 4, 16, 2, 9, 3, 13, 4, 2, 5, 15, 15, 3, 3, 11, 18, 12, 6, 8, 15, 3, 7, 9, 9, 7, 12, 11, 11, 9, 19, 19, 15, 2, 17, 18, 16, 8, 15, 3, 19, 19, 19, 1, 3, 17, 3, 8, 16, 1, 5, 19, 17, 16, 19, 6, 3, 8, 16, 11, 12, 7, 10, 13, 13, 11, 6, 2, 18, 15, 17, 8, 12, 13, 5, 12, 2, 19, 2, 19, 7, 10, 4, 14, 15, 14, 5, 1, 16, 1, 9, 10, 17, 12] adict={} for x in l: if adict.has_key(x): #then there is already an item adict[x]+=1 #increment the count by one else: #there is no key the item hasn't been seen adict[x]=1 #there is one instance so far adict {1: 4, 2: 6, 3: 8, 4: 3, 5: 4, 6: 4, 7: 5, 8: 5, 9: 6, 10: 3, 11: 6, 12: 6, 13: 4, 14: 3, 15: 7, 16: 6, 17: 7, 18: 4, 19: 9} Srinivas Iyyer wrote: Dear Jacob, thank you for your suggestion. however, i think my question was not clear. what i meant to ask in my previous question was, how to know which elements repeated and how many times they were repeated. while my question was flying, i did a small test: took a list: a [1, 1, 2, 3, 4, 2, 2] wanted to know which elements repeated and how many times: __ Do you Yahoo!? Yahoo! Mail - now with 250MB free storage. Learn more. http://info.mail.yahoo.com/mail_250 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] ascii encoding
I got this from spyce http://spyce.sourceforge.net _url_ch = re.compile(r'[^A-Za-z0-9_.!~*()-]') # RFC 2396 section 2.3 def url_encode(o, **kwargs): '''Return URL-encoded string.''' return _url_ch.sub(lambda match: %%%02X % ord(match.group(0)), str(o)) It was just the first thing I found in google python url encode Good Luck Luis N wrote: How would I best turn this string: '2005-01-24 00:00:00.0' into this string: '2005%2D01%2D24%2000%3A00%3A00%2E0' In order to call a URL. I've hunted through the standard library, but nothing seemed to jump out. Thank You. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor __ Do you Yahoo!? Meet the all-new My Yahoo! - Try it today! http://my.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] need advice on streamlining code...
I can't really think of a more elegant solution than what you have, maybe regex's but I hate those. You *can* reduce the number of lines by two, and there was a variable you never used. HTH Eric L. Howard wrote: The following block of code works, and provides the necessary output I'm looking for...but I have a feeling that it's working through sheer brute force and could be better: insideipgrepfd = os.popen(grep ifconfig_fxp0 /etc/rc.conf) insideipgrep = insideipgrepfd.readlines() insideipgrep=os.popen(grep ifconfig_fxp0 /etc/rc.conf).readlines() insideipfield, insideip = string.split(string.strip(insideipgrep[0]), =) insideip = string.split(string.strip(insideipgrep[0]), =)[1] insideipsplit = string.split(insideip, ) insideipquads = string.split(insideipsplit[1], .) insidemaskquads = string.split(insideipsplit[4], .) insideipquads=string.split(string.split(insideip, )[1],.) insidemaskquads = string.split(string.split(insideip, )[4], .) the line in /etc/rc.conf looks like: ifconfig_fxp0=inet 172.31.2.100 netmask 255.255.255.0 Any and all thoughts/pointers are appreciated. ~elh __ Do you Yahoo!? Meet the all-new My Yahoo! - Try it today! http://my.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] file-like object
I have created a file-like object out of a triple quoted string. I was wondering if there is a better way to implement readline than what I have below? It just doesn't seem like a very good way to do this. class _macroString(object): def __init__(self,s): self.macro=s self.list=self.macro.split(\n) for n,v in enumerate(self.list): self.list[n]=v+'\n' def readline(self,n=[-1]): n[0]+=1 return self.list[n[0]] def __str__(self): return str(self.list) def __len__(self): return len(self.list) __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Referer file from import
Ok I will investigate this. Thank you that is probably what I needed. I am trying to make a macro expander for python based on BOO's facility for this. I thought it was neat. In addition I think it would be helpful to simulate adding keywords so that all these bloggers talking about proposed syntax could actually try it. But mostly I want to implement the with keyword with g: append(1) append(2) append('woah') Kent Johnson wrote: You could use trackback.extract_stack() to get the current stack trace. If you inspect this from within the imported module you could probably figure out who is importing you. Do you really want the module where the import was done (the place where the import statement is)? Or are you trying to find the file containing the imported module? Kent Isr Gish wrote: Chad Crabtree wrote: Is there a way to know what the path of the file is that imported amodule? I've tried __file__ and playing with globals() but I can't seemto crack this. __ Do you Yahoo!? Take Yahoo! Mail with you! Get it on your mobile phone. http://mobile.yahoo.com/maildemo ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] file-like object
Thank you KentBot. That was what I wanted. Kent Johnson wrote: Best: use the StringIO or cStringIO module instead, this is exactly what it is for. If you really need len() you could maybe subclass StringIO to do what you want. Next best: Use an iterator. Something like this (Warning! not tested!): class _macroString(object): def __init__(self,s): self.macro=s self.list=[ line+'\n' for line in self.macro.split(\n) ] self._iter = iter(self.list) def readline(self): try: return self._iter.next() except StopIteration: return '' def __str__(self): return str(self.list) def __len__(self): return len(self.list) Note that your implementation of readline will raise IndexError when there are no more lines which is not correct behaviour. Kent __ Do you Yahoo!? Take Yahoo! Mail with you! Get it on your mobile phone. http://mobile.yahoo.com/maildemo ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Referer file from import
Is there a way to know what the path of the file is that imported a module? I've tried __file__ and playing with globals() but I can't seem to crack this. __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] flattening a list
The only problem with this if it is to big or to deeply nested then it will overflow the stack? Mario Rol wrote: nice and concise, found on comp.lang.python: def flatten(a): if not isinstance(a,(tuple,list)): return [a] if len(a)==0: return [] return flatten(a[0])+flatten(a[1:]) _ Play online games with your friends with MSN Messenger http://messenger.msn.nl/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor __ Do you Yahoo!? Yahoo! Mail - 250MB free storage. Do more. Manage less. http://info.mail.yahoo.com/mail_250 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Input to python executable code and design question
Ismael Garrido wrote: [EMAIL PROTECTED] wrote: Quoting Ismael Garrido [EMAIL PROTECTED]: I am trying to make a program that will plot functions. For that, I need to be able to get an input (the function to be plotted) and execute it. So you want the user to be able to type something like f(x) = sin(2*x) and then your program will plot it --- is that correct? Yes, that's what I want. I can understand you fear. Check out this post that Danny made in October I found it very helpful. http://mail.python.org/pipermail/tutor/2004-October/032364.html This one by kent at the same time was good too. http://mail.python.org/pipermail/tutor/2004-October/032340.html I felt this was a very good and helpful. __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] German Tutorials auf Deutsch
Jacob S. wrote: ## Spoken by Ara ## Pardon to the non-german speaking (or readers) on the list. Guten Tag. Mein Deutsch ist nicht so gut (ich habe keinen Deutsche in sieben Good Day. My German is not so good (I have writen very little german in seven years) Jahren geschreiben). Mann kann Python Tutorials auf Deutsch heir One can find Python Turorials in German here .. and .. and... http://www.freenetpages.co.uk/hp/alan.gauld/german/index.htm und http://hkn.eecs.berkeley.edu/~dyoo/python/idle_intro/index_ger.html und http://starship.python.net/crew/gherman/publications/tut-de/ finden. I habe Alan Gauld Tutorial vorgelesen. Es is gut und es abdeckt zimliche viele Themen. I have learned from Alan Gaulds Tutorial. It is good and is ? ? ? ?. ###This is where my coco the gorilla size german vocabulary meets it's end.### Ara Done with text ## Great! Another chance to try and decipher another language! Guten Tag = Good Morning Guten Tag=Good Day #coloquially Mein = My Deutsch = German (In *this* case, I guess) ist = is nicht = not so = so gut = good ich = I habe = have keinen = learned? keinen=little geschrieben=writen Deutsche = German (I guess again) in = in sieben = seven? No, that can't be it... Mann = many kann = kind? (roughly?) auf = of auf=in #in this case# heir = here OR at? und = and finden = used as end of a list finden=find/found Es = it That's all I can decipher Thanks for some fun, Jacob ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor __ Do you Yahoo!? The all-new My Yahoo! - Get yours free! http://my.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Nifty
I think it's a great idea, I would like to participate also. Brian van den Broek wrote: Jacob S. said unto the world upon 2004-12-18 21:06: I probably wouldn't be any help on projects, but I would probably learn stuff from it. I'm okay with it. Jacob Schmidt I just got in contact with Nick Parlante of the Nifty Assignments project; he's been collecting material on fun projects: http://nifty.stanford.edu/ What do others think? Private channel or not, I'm in. (at least until classes spike up again in early February) Sounds like a good way to burn through a winter. SNIP David Broadwell Hi Jacob, I've privately sent you what correspondence there has been amongst those who expressed interest. If/once we pick a common project to undertake, I will post an announcement here. (We will also likely put up a wiki page somewhere.) Best to all, Brian vdB __ Do you Yahoo!? Send a seasonal email greeting and help others. Do good. http://celebrity.mail.yahoo.com ___ Tutor maillist - [EMAIL PROTECTED] http://mail.python.org/mailman/listinfo/tutor