[Tutor] Fwd: Simple copy script

2008-04-14 Thread Que Prime
This is what I came up with after writing it out and reading the corresponding functions. I feel I'm close but something is still awry. #file copy based on input file containing filenames to be copied ## import os import shutil os.chdir('c:\\test') infile = open("in

Re: [Tutor] Fwd: Simple copy script

2008-04-14 Thread Andreas Kostyrka
line.strip() for line in file: => line will contain '\n' at the end of the string. Andreas Am Montag, den 14.04.2008, 00:08 -0700 schrieb Que Prime: > > This is what I came up with after writing it out and reading the > corresponding functions. I feel I'm close but something is still > awry. >

Re: [Tutor] Simple copy script

2008-04-14 Thread Alan Gauld
"Que Prime" <[EMAIL PROTECTED]> wrote > This is what I came up with after writing it out and reading the > corresponding functions. I feel I'm close but something is still > awry. You need to give us more information. What is still awry? Do you get any errors or is it not copyng all files? Or

[Tutor] encode unicode strings from pysqlite

2008-04-14 Thread Dinesh B Vadhia
Here is a program that SELECT's from a pysqlite database table and encode's the returned unicode strings: import sys import os import sqlite3 con = sqlite3.connect("testDB.db") cur = con.cursor() a = u'99 Cycling Swords' b = a.encode('utf-8') print b q = '%wor%' limit = 25 query = "SELECT fiel

Re: [Tutor] encode unicode strings from pysqlite

2008-04-14 Thread Kent Johnson
Dinesh B Vadhia wrote: > Here is a program that SELECT's from a pysqlite database table and > encode's the returned unicode strings: > query = "SELECT fieldB FROM testDB WHERE fieldB LIKE '%s' LIMIT '%s'" > %(q, limit) > for row in cur.execute(query): Here row is a list containing a single unic

Re: [Tutor] encode unicode strings from pysqlite

2008-04-14 Thread Dinesh B Vadhia
Hi! Kent. The row[0].encode('utf-8') works perfectly within a standalone program. But didn't work within webpy until I realized that maybe webpy is storing the row as a dictionary (which it does) and that you have to get the string by the key (ie. 'fieldB'). That worked and also webpy encodes

[Tutor] Font capture from webpages

2008-04-14 Thread Ashish Sharma
Hi , I want to find the font style,Font size written in webpage without looking into source code. Can Any one tell if there is API avalable for this in python . Thanks in Advance. Ashish Sharma ___ Tutor maillist - Tutor@python.org http://mail.python

Re: [Tutor] Font capture from webpages

2008-04-14 Thread W W
beautiful soup would do it. It's still looking into the source, though. On Mon, Apr 14, 2008 at 7:02 AM, Ashish Sharma <[EMAIL PROTECTED]> wrote: > Hi , > > I want to find the font style,Font size written in webpage without > looking into source code. > > Can Any one tell if there is API avalab

Re: [Tutor] Font capture from webpages

2008-04-14 Thread Kent Johnson
Ashish Sharma wrote: > Hi , > > I want to find the font style,Font size written in webpage without > looking into source code. Do you mean you don't want to look at the HTML/CSS for the page? If not, I guess you will have to somehow query the browser. Tools for that will be specific to the brow

[Tutor] Python Programming Tools

2008-04-14 Thread bhaaluu
A (mainly Java) programmer on a LUG mailing list asks: What is a good IDE [for Python] that has Python tools for: library management, code completion, debugging, documentation, help Since I'm not familiar with Java at all, I'm not sure how many of the things he is asking for, are even relevant f

Re: [Tutor] Tutor Digest, Vol 50, Issue 43

2008-04-14 Thread kinuthia muchane
> > Message: 1 > Date: Mon, 14 Apr 2008 01:31:41 -0700 > From: "Dinesh B Vadhia" <[EMAIL PROTECTED]> > Subject: [Tutor] encode unicode strings from pysqlite > To: > Message-ID: <[EMAIL PROTECTED]> > Content-Type: text/plain; charset="iso-8859-1" > > Here is a program that SELECT's from a pysqli

Re: [Tutor] Python Programming Tools

2008-04-14 Thread Jordan Greenberg
bhaaluu wrote: > A (mainly Java) programmer on a LUG mailing list asks: > > What is a good IDE [for Python] that has Python tools for: > > library management, > code completion, > debugging, > documentation, > help > > Since I'm not familiar with Java at all, I'm not sure how many > of

[Tutor] input and output files from terminal

2008-04-14 Thread Brain Stormer
I have a python program which works fine when run using idle but I would like call the program from the terminal. python test.py -i inputfile -o outputfile I tried with raw_input but that only works in idle. Can this be achieved? Thanks ___ Tutor maill

Re: [Tutor] input and output files from terminal

2008-04-14 Thread v2punkt0
look at the OptParse module, with this u can easily realize such things. http://docs.python.org/lib/module-optparse.html On Mon, Apr 14, 2008 at 12:55:07PM -0400, Brain Stormer wrote: > I have a python program which works fine when run using idle but I would > like call the program from the termi

Re: [Tutor] input and output files from terminal

2008-04-14 Thread linuxian iandsd
i think you need to try : cat input.txt | /usr/bin/python test.py >output.txt > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Font capture from webpages

2008-04-14 Thread linuxian iandsd
> I want to find the font style,Font size written in webpage without looking > > into source code. > > > your best bet would be your eyes. otherwise python will need to parse the source code to tell. ___ Tutor maillist - Tutor@python.org http://mail.p

Re: [Tutor] input and output files from terminal

2008-04-14 Thread bhaaluu
On Mon, Apr 14, 2008 at 12:55 PM, Brain Stormer <[EMAIL PROTECTED]> wrote: > I have a python program which works fine when run using idle but I would > like call the program from the terminal. > > python test.py -i inputfile -o outputfile > > I tried with raw_input but that only works in idle. Can

[Tutor] Pythonic way to extract delimited substrings

2008-04-14 Thread Malcolm Greene
Suggestions on the best way to extract delimited substrings strings from a larger string? Background: I have a long multi-line string with expressions delimited with '<(' and ')>' markers. I would like to extract these substrings and process them in a loop. Because the left and right delimiters a

[Tutor] Remove specific chars from a string

2008-04-14 Thread Malcolm Greene
What is the Pythonic way to remove specific chars from a string? The .translate( table[, deletechars]) method seems the most 'politically correct' and also the most complicated. My ideas: 1. For each char to be removed, do a .replace( char_to_delete, '' ) 2. Do a .split( str_of_chars_to_delete )

Re: [Tutor] input and output files from terminal

2008-04-14 Thread Brain Stormer
I used the optparse module since that is exactly what I wanted. Here is my code: import sys from optparse import OptionParser import os parser = OptionParser() parser.add_option("-i", "--input", dest="infile", help="input FILE to convert", metavar="FILE") parser.add_option("-o", "--output", dest

Re: [Tutor] Python Programming Tools

2008-04-14 Thread Alan Gauld
"Jordan Greenberg" <[EMAIL PROTECTED]> wrote > > What is a good IDE [for Python] that has Python tools for: > > > > library management, > > code completion, > > debugging, > > documentation, > > help Depending on what he wants in the way of "Library Management" then Pythonwin will give him all o

Re: [Tutor] Font capture from webpages

2008-04-14 Thread Alan Gauld
"Ashish Sharma" <[EMAIL PROTECTED]> wrote > I want to find the font style,Font size written in webpage without > looking into source code. Do you mean you need to find the actual font used in the browser regardless of the settings in the HTML/CSS source? On Windows you can probably do that by

Re: [Tutor] input and output files from terminal

2008-04-14 Thread Alan Gauld
"Brain Stormer" <[EMAIL PROTECTED]> wrote >I have a python program which works fine when run using idle but I >would > like call the program from the terminal. > > python test.py -i inputfile -o outputfile Easier to use file redirection: python test.py < inputfile > outputfile The -i flag in

Re: [Tutor] Pythonic way to extract delimited substrings

2008-04-14 Thread Kent Johnson
Malcolm Greene wrote: > Suggestions on the best way to extract delimited substrings strings from > a larger string? > > Background: I have a long multi-line string with expressions delimited > with '<(' and ')>' markers. I would like to extract these substrings and > process them in a loop. > Wha

Re: [Tutor] Remove specific chars from a string

2008-04-14 Thread Kent Johnson
Malcolm Greene wrote: > What is the Pythonic way to remove specific chars from a string? The > .translate( table[, deletechars]) method seems the most 'politically > correct' and also the most complicated. Most 'correct' and also by far the fastest. This recipe makes it a bit easier to use: http:

Re: [Tutor] Pythonic way to extract delimited substrings

2008-04-14 Thread Alan Gauld
"Malcolm Greene" <[EMAIL PROTECTED]> wrote in > Background: I have a long multi-line string with expressions > delimited > with '<(' and ')>' markers. I would like to extract these substrings > and > process them in a loop. > > I know how to do this task with regular expressions, but I'm always

Re: [Tutor] Remove specific chars from a string

2008-04-14 Thread Alan Gauld
"Malcolm Greene" <[EMAIL PROTECTED]> wrote > What is the Pythonic way to remove specific chars from a string? The > .translate( table[, deletechars]) method seems the most 'politically > correct' and also the most complicated. Assuming you have lots of different characters and not just one to re

Re: [Tutor] Remove specific chars from a string

2008-04-14 Thread Dick Moores
At 12:04 PM 4/14/2008, Kent Johnson wrote: Malcolm Greene wrote: > What is the Pythonic way to remove specific chars from a string? The > .translate( table[, deletechars]) method seems the most 'politically > correct' and also the most complicated. Most 'correct' and also by far the fastest. This

Re: [Tutor] Remove specific chars from a string

2008-04-14 Thread Kent Johnson
Dick Moores wrote: > def sigDigits(n): > """ > Strips any real decimal (as string) to just its significant digits, > then returns its length, the number of significant digits. > Examples: "-345" -> "345" -> 3; > "3.000" -> "3000" -> 4 > "0.0001234" -> "1234" -> 4; > "10.

[Tutor] Best practice: Use % operator or locale.format?

2008-04-14 Thread python
Does the % operator always respect locale or should one use locale.format() instead? Are there guidelines where one should use one string formatting technique vs. another? Thanks! Malcolm ___ Tutor maillist - Tutor@python.org http://mail.python.org/ma

Re: [Tutor] Remove specific chars from a string

2008-04-14 Thread Dick Moores
At 01:39 PM 4/14/2008, Kent Johnson wrote: Dick Moores wrote: def sigDigits(n):     """     Strips any real decimal (as string) to just its significant digits,     then returns its length, the number of significant digits.     Examples: "-345" -> "345" -> 3;     "3.000" -> "3000" -> 4     "0.0001

[Tutor] setting program configuration for all files and modules of a program

2008-04-14 Thread Tim Michelsen
Hello, I am building a simple GUI for a calculation program. I am using config files (*.cfg) and reading them in with ConfigParser. This works well because I have nearly all code in 1 text file. But I would like to modularize my code and separate the GUI code from the functional code that provid

Re: [Tutor] Conventions for code snippets for debugging and testing?

2008-04-14 Thread Ricardo Aráoz
Robert Kirkpatrick wrote: > Hi All, > > Just wondering if there are any basic conventions for including code > snippets that are for testing / debugging only? > > For example, you could set a boolean variable called DEBUG, then have > snippets of code like: > > if DEBUG: > do stuff > else: >

Re: [Tutor] setting program configuration for all files and modules ofa program

2008-04-14 Thread Alan Gauld
"Tim Michelsen" <[EMAIL PROTECTED]> wrote > But I would like to modularize my code and separate the GUI code > from > the functional code that provides the calculation operations. This > will > help to expand the functionality at a later stage. I want to achieve > this through splitting the code

[Tutor] cut all decimal places with zeros

2008-04-14 Thread Tim Michelsen
Hello, how can I suppress the decimal places for (only those) numbers whos decimal places are zero (0)? Example: CODE In [1]: m = 2.0 In [2]: n = 2.56789080 In [3]: n_format = '%.4f' %n In [4]: n_format Out[4]: '2.5679' In [5]: m_format = '%.4f' %m In [6]: m_format Out[6]: '2.00

Re: [Tutor] setting program configuration for all files and modules ofa program

2008-04-14 Thread Tim Michelsen
> Yes, thats the way I'd recommend. >> Is there a more decent and elegant way? I don't know. I was just asking how other programmers achive this efficiently. > Another option is to have the config settiongs in a normal > Python module and just import it. That is less appealing if > the config fi

[Tutor] Open url in browser window

2008-04-14 Thread Michael Finlayson
Hi all, This is a serious newbie question. I started this morning. I need to do two simple things (simple on a PC anyway), and I would like to ask the group if it is even possible on a Mac before I go through learning Python. I am a partner in an online training company. All training is del

Re: [Tutor] cut all decimal places with zeros

2008-04-14 Thread Kent Johnson
Tim Michelsen wrote: > Hello, > how can I suppress the decimal places for (only those) numbers whos > decimal places are zero (0)? I don't know how to do this with just string formatting but I think ('%.4f' % n).rstrip('.0') will do what you want. Kent ___

Re: [Tutor] setting program configuration for all files and modules of a program

2008-04-14 Thread Kent Johnson
Tim Michelsen wrote: > What is the state of the art in storing and parsing configuraions in > python programs? It is pretty common to have a configuration module that is imported wherever the configuration is needed. This is simple but it is essentially global state and shares some of the disad