Re: [Tutor] string to integer
nums = [ch for ch in aString if ch in string.digits] I'd spell that nums = [ch for ch in aString if ch.isdigit()] Now I had a look for a digit() method but never notoced the isdigit() one. Thanks Brian. Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] MySQL api does not accept variable.
Hello, This is a snip of my code: code def sql_listusers(hostname, dbusername, dbpassword, dbbase, dbasename): try: conn = MySQLdb.connect (host = hostname, user = dbusername, passwd = dbpassword, db = dbbase) cursor = conn.cursor () cursor.execute ( use %s , (dbasename)) # --- here is the problem cursor.execute( select * from ftpuser; ) rows = cursor.fetchall() print print USER DATABASE LIST print -- for row in rows: print %s, %s % (row[0], row[1]) cursor.close () print -- print conn.close () except MySQLdb.Error, e: print Error %d: %s % (e.args[0], e.args[1]) sys.exit (1) /code Everything works fine in this function, except that fact that the (dbasename) variable is not accepted. I don't know why.. this is the syntax I used from the start in order to pass arguments inside to the mysql command line, and everything worked fine until now. The first version of the program did not use a variable there. Is there any obvious mistake that I can't see? Happy new year to the list members, Best Regards -- Panagiotis ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Excel files to Tab delim files
Hi, If you run python on windows, you may also take the control of office (word,excel) and may others tools, for example image you have a mysheet.xls in C import pythoncom, win32com.client,os pythoncom.CoInitializeEx(pythoncom.COINIT_APARTMENTTHREADED) excelapp = win32com.client.gencache.EnsureDispatch(Excel.Application) excelapp.Workbooks.Open(Filename=C:\\mysheet.xls ) excelapp.Range('A1').Select() value = excelapp.ActiveCell.FormulaR1C1 #closing, strong way or the process may stay in the back ground excelapp.ActiveWorkbook.Close(False) excelapp.Quit() del excelapp value contains now what there is in A1, to see the syntax just record a macro on excel and than edit it. Except for the initialization of the Dispatcher the instruction are the same, so you can almost copy and paste. Carlo this work fine in python2.3 too :-) what is ITER? www.iter.org -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Srinivas Iyyer Sent: Thursday, January 05, 2006 11:35 PM To: tutor@python.org Subject: [Tutor] Excel files to Tab delim files Dear group, is there any library available that would convert over 2000 .xls files to tab delim text files. I have over 2000 Excel files and I want to convert them to tab delim files, which has become a pain in brain. Thanks Srini __ Yahoo! DSL - Something to write home about. Just $16.99/mo. or less. dsl.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] MySQL api does not accept variable.
def sql_listusers(hostname, dbusername, dbpassword, dbbase, dbasename): try: conn = MySQLdb.connect (host = hostname, user = dbusername, passwd = dbpassword, db = dbbase) cursor = conn.cursor () cursor.execute ( use %s , (dbasename)) # --- here is the problem Everything works fine in this function, except that fact that the (dbasename) variable is not accepted. I don't know why.. What error are you getting. Are you sure the value in dbasename is *exactly* the same as the version that worked with a hard coded value? version of the program did not use a variable there. Is there any obvious mistake that I can't see? Given that we can't see what you are passing into the function its hard to tell. On a general note, given that your function claims to list users it would seem reasonable that you could already have a connection to the database and you would want to pass that in rather than do all the connect stuff inside the function. Otherwise you will have to close the database connection before listing the users etc. That seems pretty inconvenient to me. I'd expect the function interface to look more like: def sql_listUsers(dbConnection, dbName): ... Just a thought, Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Avoiding repetetive pattern match in re module
Intercodes wrote: Hello everyone, Iam new to this mailing list as well as python(uptime-3 weeks).Today I learnt about RE from http://www.amk.ca/python/howto/regex/ http://www.amk.ca/python/howto/regex/%22RE%27s.This one was really helpful. I started working out with few examples on my own. The first one was to collect all the HTML tags used in an HTML file. I get the output but with tags repeated. I want to display all the tags used in a file ,but no repetitions.Say the output to one of the HTML file I got was : htmllink abrabr You might consider Beautiful Soup or another HTML parser to collect the tags. Then use a set to find unique tags. For example (Python 2.4 version), import urllib from BeautifulSoup import BeautifulSoup as BS data = urllib.urlopen('http://www.python.org').read() bs = BS(data) help(bs.fetch) Help on method fetch in module BeautifulSoup: fetch(self, name=None, attrs={}, recursive=True, text=None, limit=None) method of BeautifulSoup.BeautifulSoup instance Extracts a list of Tag objects that match the given criteria. You can specify the name of the Tag and any attributes you want the Tag to have. tags = set(tag.name for tag in bs.fetch()) sorted(tags) ['a', 'b', 'body', 'br', 'center', 'div', 'font', 'form', 'h4', 'head', 'html', 'i', 'img', 'input', 'li', 'link', 'meta', 'p', 'small', 'table', 'td', 'title', 'tr', 'ul'] http://www.crummy.com/software/BeautifulSoup/index.html Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] MySQL api does not accept variable.
Hello, Thank you for the reply. You can browse the entire script code[1]. The truth is that I did not think about it. The speed is acceptable for me, but as you point you out, it does not make much sense. I can't think of the con's and the pro's of keeping open the mysql connection when the script starts and close it when it ends.. except the reply speed and the system resources maybe, but with today's computers (I run this script at a p4 2.6 Ghz 512 RAM with a lot free memory) I don't think that there will be any real difference. But, as a starter I am interested in writing -- so called -- clean code and follow the right way to do things. Hence if there is a standard practise I'd like to follow it. Thank you for your time, regards [1] http://beast.merseine.nu/files/other/vuhandle-0.1.html On 1/6/06, Alan Gauld [EMAIL PROTECTED] wrote: def sql_listusers(hostname, dbusername, dbpassword, dbbase, dbasename): try: conn = MySQLdb.connect (host = hostname, user = dbusername, passwd = dbpassword, db = dbbase) cursor = conn.cursor () cursor.execute ( use %s , (dbasename)) # --- here is the problem Everything works fine in this function, except that fact that the (dbasename) variable is not accepted. I don't know why.. What error are you getting. Are you sure the value in dbasename is *exactly* the same as the version that worked with a hard coded value? version of the program did not use a variable there. Is there any obvious mistake that I can't see? Given that we can't see what you are passing into the function its hard to tell. On a general note, given that your function claims to list users it would seem reasonable that you could already have a connection to the database and you would want to pass that in rather than do all the connect stuff inside the function. Otherwise you will have to close the database connection before listing the users etc. That seems pretty inconvenient to me. I'd expect the function interface to look more like: def sql_listUsers(dbConnection, dbName): ... Just a thought, Alan G. -- Panagiotis ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Web-log, not blog
Hello. I am trying to find some Pythonmodules to work with some webserver logs. I have found http://www.mnot.net/python/WebLog/, but it is very old (from 1999). And when I try to serach in Google and so forth, all I get is Python weblogs as in blogs. Do you have some suggestions of other sites about analyzing webtraffic with Python? Thanks in advance -- This email has been scanned for viruses spam by Decna as - www.decna.no Denne e-posten er sjekket for virus spam av Decna as - www.decna.no ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Web-log, not blog
Øyvind wrote: Hello. I am trying to find some Pythonmodules to work with some webserver logs. I have found http://www.mnot.net/python/WebLog/, but it is very old (from 1999). And when I try to serach in Google and so forth, all I get is Python weblogs as in blogs. Do you have some suggestions of other sites about analyzing webtraffic with Python? Googling +python webserver log analyze and checking PyPI yielded a few more choices: http://mithrandr.moria.org/code/sisynala/ http://www.phil-schwartz.com/scratchy.spy Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] MySQL api does not accept variable.
I can't think of the con's and the pro's of keeping open the mysql connection when the script starts and close it when it ends.. The reasoning is that you want to open the connection at the start of a script do all your processing then close it. In between you might want to add data, create new tables, select data and other thoings, including getting a list of users. Now with your code you would need to close the connection before calling your function then reopen it again to fiunish off the rest of the work. Its OK if your function is only ever used in a single script and is the only access to the database, but if you ever want to get the users in any other program your function is almost unusably inconvenient. computers (I run this script at a p4 2.6 Ghz 512 RAM with a lot free memory) I don't think that there will be any real difference. You are quite correct for a single user on a modern PC. But... It would make a difference in a high volume environment with many users (like a web application say), or on an older machine but the real value is when you want to use the function as part of a bigger program that has already opened the connection to the database. Regards, Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] IDLE doesn't start in Python 2.4 in windows XP
Hi Danny, I was following some of your suggestions in making my IDLE work in Windows XP laptop. (http://mail.python.org/pipermail/tutor/2005-January/034683.html). First, i changed the IDLE shortcut path: from C:\Python24\python.exe TO C:\Python24\python.exe C:\Python24\Lib\idlelib\idle.pyw -n Now Idle works but throws up a lot of warning etc. in a seperate black window. # Warning: configHandler.py - IdleConf.GetThemeDict - problem retrieving theme element 'builtin-background' from theme 'sp'. returning default value: '#ff' Warning: configHandler.py - IdleConf.GetThemeDict - problem retrieving theme element 'builtin-foreground' from theme 'sp'. returning default value: '#00' The same content apparently repeatedly printed for 5 times i guess in the same black window. ### When I close that window the whole IDLE disappears. Is this the correct way or are there some modifications incorporated now. Looking forward to your input __ Yahoo! DSL Something to write home about. Just $16.99/mo. or less. dsl.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] IDLE doesn't start in Python 2.4 in windows XP
On Fri, 6 Jan 2006, Srinivas Iyyer wrote: Hi Danny, I was following some of your suggestions in making my IDLE work in Windows XP laptop. (http://mail.python.org/pipermail/tutor/2005-January/034683.html). Hi Srinivas, That suggestion, to change the desktop shortcut, wasn't mine. *grin* But look near the bottom of that message for my reply about the configHandler problems. What's going on is probably bug 1080387: http://sourceforge.net/tracker/index.php?func=detailaid=1080387group_id=5470atid=105470 If you move off your '.idlerc' in your home directory to somewhere else, IDLE should be able to regenerate its configuration files. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] iterate over daterange
Hello I have a startdate and an enddate and I want to iterate over all days in between the two there doesn't seem to be a range function for dates?!? i.e. currently I am going through integers with something like this: = startdate = datetime.date(2006,1,1) enddate = datetime.date(2006,10,19) for i in range((enddate-startdate).days + 1): currentdate = startdate + datetime.timedelta(days=i) = this seems so 'unpythonic', there surely must be a better way, no? thx, -frank ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] iterate over daterange
On Fri, 6 Jan 2006, captnswing wrote: Hello I have a startdate and an enddate and I want to iterate over all days in between the two there doesn't seem to be a range function for dates?!? Sounds like a good application for a generator: # def daterange(from_date, to_date, step=None): from datetime import timedelta if step is None: step = timedelta(1) yield_date = from_date while yield_date to_date: yield yield_date yield_date = yield_date+step # To use: # import datetime start = datetime.date(2006,1,6) end = datetime.date(2006,1,13) print default: one-day step: for dx in daterange(start,end): print dx print two-day step: for dx in daterange(start, end, datetime.timedelta(2)): print dx # prints: default: one-day step: 2006-01-06 2006-01-07 2006-01-08 2006-01-09 2006-01-10 2006-01-11 2006-01-12 two-day step: 2006-01-06 2006-01-08 2006-01-10 2006-01-12 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Nearly there
This is itching at me, too. On Fri, 6 Jan 2006, John Corry wrote: Can anyone understand or tell me why this works but the following code does not:- import win32api filename = testprint.txt fileobj=open (filename, w) fileobj.write (This is a test) fileobj.close() win32api.ShellExecute ( 0, print, filename, None, ., 0 ) I'm wondering if ShellExecute needs a full path to find it under W98. Try this; add to the top of your code: import os.path and change your ShellExecute to this: win32api.ShellExecute ( 0, print, os.path.abspath(filename), None, ., 0 ) I have no idea if this will work; and the error message you're getting, The code above gives me the error: (31, 'ShellExecute', 'A device attached to the system is not functioning.') doesn't seem to indicate it, but it's one less thing. I'd love to know the answer when you get it. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Python upgrade from 2.3 to 2.4
Hello Srinivas, You can install both versions on the same platform,in separate directories,and start them individually as any other else application.Obviously each one will rely on the modules with which was coming when installed.(And,if you installed further extensions,they will work properly with the installation corresponding to the version of Python that they were designed to work correctly for.).If you need even one module alone that requires a new installation,i suggest to clean install in spite of updrading.(unless you have disk space problems most of the time.) Basically,this is the reason for which I suggest to clean install the new version,then install the new stuff packing it within its directories;and to keep the old ones alone,where you installed them,with the old version.Another point:if you need,adjust your PATH in order to point to your favourite version the more conveniently. My configuration : Python 2.3.5 Enthought Edition in C:\PYTHON23; Python 2.4 (with wxPython,BOAConstructor) in C:\py24 (sic!) Sorry,I only use IDLE on Linux,so I'm unaware of this strange behaviour of its on Windows,but I would review that the same,if I only knew what Windows version you are using and the build number of the Python version (the third number after 2.4) Cheers Ivan ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor