Re: [Tutor] Are there any MAC OSX python users here?

2007-01-22 Thread Markus Rosenstihl


Am 22.01.2007 um 10:23 schrieb ALAN GAULD:


Forwarding to list.

--- Tony Cappellini <[EMAIL PROTECTED]> wrote:


They need to start Applications-Utilities->Terminal

It turned out that the users needed to change the
permissions to +x, then the script would be
invoked normally.


Ah, but you specifically said it was a command
line program, so I thought you wanted to run it
that way. :-)


writing simple gui launcher to get around that problem.


You could use Applescript for that.


Or, for simple scripts to be started by "double clicking":

http://www.sveinbjorn.org/platypus

It's a lovely program.

regards

Markus


PGP.sig
Description: Signierter Teil der Nachricht
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Running drPython and other Pythonscript on Macintosh OS/X

2006-12-06 Thread Markus Rosenstihl

Am 05.12.2006 um 09:44 schrieb Anders Persson:

> Hi!
>
> I try to learn my son Development using Python.
> I have found that drPython was a great enviroment and easy for him to
> understand.
>
> Is't a problem running om Macintosh OS/X i have to start on 
> commandline,
> OS/X
> dosen't understand when i clicked on the drPython.py files.
>
> I have found this is same for all pythonfiles on OS/X, does somone know
> how a
> tell a OS/X system that .py means run Python.
>


Try to right click (Ctrl + Klick) and open it with PythonLauncher. I 
don't know if that is
installed with a stock python but I think so.
If that is working you can get the Info panel of that file (Apple + i) 
and select PythonLauncher
in the "open with" section…

HTH
Markus

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Need to be taught a trick or two about printing in neat columns

2006-11-02 Thread Markus Rosenstihl


Am 02.11.2006 um 15:14 schrieb Dick Moores:

> At 03:31 AM 11/2/2006, you wrote:
>> At 03:13 AM 11/2/2006, Kent Johnson wrote:
>>> Luke Paireepinart wrote:
 Instead of helping you with your specific problem, I'll give you 
 this
 information and see what you can make of it.

>>> print 'a'.ljust(20)+'b'.ljust(20)
 a   b
>>> print 'carrah'.ljust(20)+'foobar'.ljust(20)
 carrah  foobar
>>>
>>> Another way to do this is with string formatting, I think it is a 
>>> more
>>> readable and flexible solution:
>>>
>>> In [1]: print '%-20s %-20s' % ('a', 'b')
>>> ab
>>>
>>> In [2]: print '%-20s %-20s' % ('carrah', 'foobar')
>>> carrah   foobar
>>>
>>> See this page for details:
>>> http://docs.python.org/lib/typesseq-strings.html
>>
>> Thanks, Kent. I agree. So now that function has become
>>
>> def printListOfAllUnitsAndAbbreviations():
>>  """
>>  Prints a 3-column list of all units and their abbreviations,
>> but not their categories.
>>  """
>>  lstAll = allUnitsAndTheirAbbreviationsAndCategories()
>>  for i in range(0, len(lstAll)-1 ,3):
>>  print '%-27s %-27s %-27s' % (lstAll[i][2:],
>> lstAll[i+1][2:], lstAll[i+2][2:])
>>  print
>
> Oops! Got overconfident. Didn't check to see if it actually printed
> the whole list. It didn't. Left off "rad: radian", because there are
> 46 items in the list (46%3 is 1, not 0). So now the only way I could
> see to print all 46 was to add 2 empty dummies to make 48, which is
> divisible by 3, and also modify the range in the second function. Is
> there a better way, which is also a general solution that will work
> when I subtract or add to the list? See the two  modified functions 
> below.
>
> Dick
>
>
> def allUnitsAndTheirAbbreviationsAndCategories():
>  """
>  A list of all units, their abbreviations and categories.
>  """
>  abbs = [
>  'l mi: mile',
>  'l km: kilometer',
>  'l m: meter',
>  'l yd: yard',
>  'l ft: foot',
>  'l in: inch',
>  'l cm: centimeter',
>  'l mm: millimeter',
>  'l fur: furlong',
>  'l lea: league',
>  'l nm: nautical mile',
>  'a ha: hectare',
>  'a ac: acre',
>  'a mi2: square mile',
>  'a km2: square kilometer',
>  'a m2: square meter',
>  'a yd2: square yard',
>  'a ft2: square foot',
>  'a in2: square inch',
>  'a cm2: square centimeter',
>  'w kg: kilogram',
>  'w lb: pound',
>  'w gm: gram',
>  'w oz: ounce',
>  'v qt: quart',
>  'v oz: ounce',
>  'v l: liter',
>  'v ml: milliliter',
>  'v gal: gallon',
>  'v tbsp: tablespoon',
>  'v tsp: teaspoon',
>  'v impgal: Imperial Gallon',
>  'v yd3: cubic yard',
>  'v m3: cubic meter',
>  'v ft3: cubic foot',
>  'v mi3: cubic mile',
>  'v km3: cubic kilometer',
>  't F: Fahrenheit',
>  't C: Celsius',
>  't K: Kelvin',
>  's mph: miles per hour',
>  's knots: knots',
>  's mps: miles per second',
>  's fps: feet per second',
>  'd deg: degree',
>  'd rad: radian',
>  '   ',
>  '   '
>  ]
>  return abbs
>
> def printListOfAllUnitsAndAbbreviations():
>  """
>  Prints a 3-column list of all units and their abbreviations,
> but not their categories.
>  """
>  lstAll = allUnitsAndTheirAbbreviationsAndCategories()
>  for i in range(0, len(lstAll), 3):
>  print '%-27s %-27s %-27s' % (lstAll[i][2:],
> lstAll[i+1][2:], lstAll[i+2][2:])
>  print
>


Try somthing like this:

In [32]: a=range(100)
In [33]: for i in range(0,len(a)):
: print '%-27s'%a[i],
: if (i+1)%3 == 0: print "\n"

0   1   2

3   4   5
...
93  94  95

96  97  98

99


Note the comma after the first print statement

Regards
Markus

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] question about pylab

2006-10-31 Thread Markus Rosenstihl

Am 31.10.2006 um 08:35 schrieb shawn bright:

> hey there,
> i am trying to use a graph and chart app called matplotlib, but i 
> cannot figgure out how to have it plot a simple chart over time.
> the docs say to use the function plot_date() but i cannot seem to get 
> the values to agree.
> I am sending datetimes to the charting app for x, and the y is a list 
> of values that the our equipment reports.
> sometimes there are lots of reports in a row, and i would like the 
> chart to show it like that instead of plotting out every time as an 
> evenly spaced tick on the x scale. Does this make any sense, what i am 
> after here? Anyway, if any of you have much experience with this sort 
> of thing, or may suggest a package (pylab is my first attempt) please 
> send me some advice.
>
> thanks for your time,
> sk

I am not sure if I get it right, could you give us some sample data   
and some code what you have tried?
I never used plot_date, but I could give it a try.

Regards,
Markus

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Clean up loop and search in a list

2005-10-13 Thread Markus Rosenstihl
Thank you  for the fast reply

Am 13.10.2005 um 19:43 schrieb Kent Johnson:


>   if len(filter(re_name.search, line)) > 0:
> could be written
>   if re_name.search(line):

this is not working  because I am parsing a line in a list (i think):

Traceback (most recent call last):
   File "telekom2.py", line 42, in ?
 if re_month.search(line):
TypeError: expected string or buffer


> or even, since the re is just fixed text,
>   if phone[name] in line:

this won't match anything, the number is only a part of a string...

I read the file in with

read_file = csv.reader(open(sys.argv[1], 'r'), delimiter="\t")


The input file is something like this (6 lines)


"Sonstige Leistungen des Konzerns Deutsche Telekom" "Inkasso"   
"T-Online 
International AG"   "Ohne Anschluss""---"   "---"   "T-Online dsl 
flat max   
   Monatliche Grundgebühr"  "19112" "---"   "25,8100"   "25,81" "16"

"Monatliche Beträge vom 01.09.2005 bis 30.09.2005"  "ISDN"  "Deutsche 
Telekom AG" "Rufnummer" "1234561"   "---"   "T-ISDN xxl sunday 
(monatlicherGrundpreis)""19487" "---"   "26,9600"   "26,96" "16"

"Monatliche Beträge vom 01.09.2005 bis 30.09.2005"  "T-DSL" "Deutsche 
Telekom AG" "Rufnummer" "1234561"   "---"   "Monatlicher Grundpreis 
   
FastPath für T-DSL" "63215" "---"   "0,8500""0,85"  "16"

"Verbindungen Deutsche Telekom vom 17.08.2005 bis 
17.08.2005" "ISDN"  "Deutsche Telekom 
AG" "Rufnummer" "012341234561"  "2" "Verbindungen zum  
Service 0190x"  "03288" "21""0,0533""1,12"  "16"

"Verbindungen Deutsche Telekom vom 17.08.2005 bis 
14.09.2005" "ISDN"  "Deutsche Telekom 
AG" "Rufnummer" "012341234561"  "23""Verbindungen zu T-Mobile  
AktivPlus xxl sunday"   "19483" "190"   "0,1719""32,66" "16"

"Verbindungen Deutsche Telekom vom 17.08.2005 bis 
14.09.2005" "ISDN"  "Deutsche Telekom 
AG" "Rufnummer" "012341234561"  "2" "Deutschlandverb. AktivPlus 
xxlsunday Mo-Fr Hauptzeit"  "19477" "11""0,0396""0,44"  "16"

>
>>
>> Is there for example a way to search the whole list and give back all
>> the line numbers containing a string?
>   [ i for i, line in enumerate(rechnung) if "Monatliche" in line ]

hm, it doesn't match:

 >>> import csv
 >>> rechnung=list(csv.reader(open('2005_08_Rechnung.dat', 'r'), 
delimiter="\t"))
 >>> [ i for i, line in enumerate(rechnung) if "Monatliche" in line ]
[]


This matches all lines, not only the ones which have "Moantliche":

 >>> [ i for i, line in enumerate(rechnung) if re_month.search in line ]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 
38, 39, 40]


>
> Kent
>>
>> Regards,
>> Markus
>>
>>
>>
>> phone={ "Markus":"1234561",\
>>  "Eckhard":"1234562",\
>>  "Robert":"1234563",\
>>  "Lei":"1234564"
>>  }
>>
>>
>>
>> for name in phone.keys():# loop through the list for all names
>>  euro=0 # set at each run to 0
>>  i=0 # Line number
>>
>>  # compile REs
>>  re_name = re.compile(phone[name])
>>  re_month=re.compile("Monatliche")
>>  re_misc=re.compile("Sonstige")
>>  
>>  for line in rechnung:
>>  if len(filter(re_month.search, line)) == 0: # skip the 
>> monthly
>> costs
>> #if "Monatliche" in line:
>>  if len(filter(re_name.search, line)) > 0 and
>> len(filter(re_misc.search, line)) == 0:
>> #if phone[name] in line:
>>  euro += float(rechnung[i][10].replace( ',' , 
>> '.'))
>>  if len(filter(re_misc.search, line)) > 0:   # misc 
>> services
>>  if i not in misc_list: # add misc fees only once
>>  misc_list.append(i)
>>  misc += float(rechnung[i][10].replace( 
>> ',' , '.'))
>>  elif len(filter(re_month.search, line)) > 0:
>>  if i not in monthly_list: # add monthly occuring fees 
>> only once
>>  monthly_list.append(i)
>>  monthly += float(rechnung[i][10].replace( ',' , 
>> '.')) # replace
>> commata with dots then add to the sum
>>  i=i+1   
>>  per_user = ( euro + ( monthly + misc )/ divider )*1.16
>>  total += per_user
>>  print name,": ", per_user
>>
>>
>>
>> --
>> If everything seems to be going well,
>> you  obviously don't know what the hell is going on
>>
>> ___
>> 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@pyth

[Tutor] Clean up loop and search in a list

2005-10-13 Thread Markus Rosenstihl
Hi,
I wrote a program (see below) to analyse my phone bill, which is shared 
by three others and I don't  know if there is a way to make lines like 
this nicer:
if len(filter(re_name.search, line)) > 0 and len(filter(re_misc.search, 
line)) == 0

Is there for example a way to search the whole list and give back all 
the line numbers containing a string?

Regards,
Markus



phone={ "Markus":"1234561",\
"Eckhard":"1234562",\
"Robert":"1234563",\
"Lei":"1234564"
}



for name in phone.keys():   # loop through the list for all names
euro=0 # set at each run to 0
i=0 # Line number

# compile REs
re_name = re.compile(phone[name])
re_month=re.compile("Monatliche")
re_misc=re.compile("Sonstige")

for line in rechnung:
if len(filter(re_month.search, line)) == 0: # skip the 
monthly 
costs
#   if "Monatliche" in line:
if len(filter(re_name.search, line)) > 0 and 
len(filter(re_misc.search, line)) == 0:
#   if phone[name] in line:
euro += float(rechnung[i][10].replace( ',' , 
'.'))
if len(filter(re_misc.search, line)) > 0:   # misc 
services
if i not in misc_list: # add misc fees only once
misc_list.append(i)
misc += float(rechnung[i][10].replace( 
',' , '.'))
elif len(filter(re_month.search, line)) > 0:
if i not in monthly_list: # add monthly occuring fees 
only once
monthly_list.append(i)
monthly += float(rechnung[i][10].replace( ',' , 
'.')) # replace 
commata with dots then add to the sum
i=i+1   
per_user = ( euro + ( monthly + misc )/ divider )*1.16
total += per_user
print name,": ", per_user



--
If everything seems to be going well,
you  obviously don't know what the hell is going on

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor