Re: [Tutor] using easy_install to download eggs

2009-10-05 Thread Tim Michelsen
Hi,
thanks for the hint.

 pip (http://pypi.python.org/pypi/pip/) is a drop-in replacement for the
 easy_install tool and can do that.
 
 Just run easy_install pip and set an environment variable
 PIP_DOWNLOAD_CACHE to the path you want pip to store the files. Note
 that the cache won't work with dependencies that checkout from a source
 code repository (like svn/git/hg/bzr).

I tried this.

It saves the downloaded packages in a form of:
http%3A%2F%2Fpypi.python.org%2Fpackages%2Fsource%2FB%2FBareNecessities%
2FBareNecessities-0.2.2.tar.gz.content-type
http%3A%2F%2Fpypi.python.org%2Fpackages%2Fsource%2FB%2FBareNecessities%
2FBareNecessities-0.2.2.tar.gz

I was looking for *.egs or *.exe pachages.

Any ideas?

Regards,
Timmie

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] using easy_install to download eggs

2009-10-04 Thread Tim Michelsen
Hello,
I would like to use easy_install to cache packages registered at PyPi locally.

How can I do this for packages?

I tried the hints from:
http://peak.telecommunity.com/DevCenter/EasyInstall#installing-on-un-networked-machines

It worked for some packages.
But for others, the command

easy_install -zxad. mercurial

just creates a subdirectory and not an *.egg file.

How can I
1) use easy_install to download packages from PyPi to a locally saved egg-file?
2) use easy_install to download archinves (*.tar.gz / *.zip) to download the
respective software package from the link indicated on PyPi?

Thanks in advance,
Timmie

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] how to reference a function itself when accessing its private functions?

2009-05-04 Thread Tim Michelsen

Dear Tutors and fellow pythonistas,
I would like to get access to the private methods of my function.

For instance:
Who can I reference the docstring of a function within the function itself?

Please have a look at the code below and assist me.

Thanks and regards,
Timmie

 CODE ###

s = 'hello'

def show(str):
prints str
print str

return str



def show2(str):
prints str
print str
d = self.__doc__
print d

 show2(s)
hello
---
NameError Traceback (most recent call last)

ipython console in module()

ipython console in show2(str)

NameError: global name 'self' is not defined

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


Re: [Tutor] Webpy vs Django

2009-04-20 Thread Tim Michelsen

I can recommend you web2py:
http://www.web2py.com/

It has been designed for didactical needs and has a low learning curve.

Look at the manual extarct for an idea:
Free manual chapters - 
http://mdp.cti.depaul.edu/examples/static/web2py_manual_cut.pdf


or check the docs:
http://www.web2py.com/examples/default/docs

All the best,
Timmie

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


[Tutor] creating a list of all imported modules

2009-03-09 Thread Tim Michelsen

Hello,


how do I create a list of all modules imported by   my module/script?

I am looking for something like %who in Ipython.

Thanks for your help in advance.

Regards,
Timmie

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


Re: [Tutor] Difference in minutes between two time stamps

2009-03-03 Thread Tim Michelsen

  import datetime

s = '09:35:23'
datetime.datetime.strptime(s, '%H:%M:%S')

datetime.datetime(1900, 1, 1, 9, 35, 23)

Can you figure out how to proceed from there?

In case she doesn't know:

import datetime as dt
start=09:35:23
end=10:23:00

start_dt = dt.datetime.strptime(start, '%H:%M:%S')

end_dt = dt.datetime.strptime(end, '%H:%M:%S')

diff.seconds/60

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


Re: [Tutor] Difference in minutes between two time stamps

2009-03-03 Thread Tim Michelsen



  import datetime

s = '09:35:23'
datetime.datetime.strptime(s, '%H:%M:%S')

datetime.datetime(1900, 1, 1, 9, 35, 23)

Can you figure out how to proceed from there?

In case she doesn't know:

import datetime as dt
start=09:35:23
end=10:23:00

start_dt = dt.datetime.strptime(start, '%H:%M:%S')

end_dt = dt.datetime.strptime(end, '%H:%M:%S')


I forgot to paste in between:
diff = (end_dt - start_dt)


diff.seconds/60


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


[Tutor] using windows wide proxy settings

2008-12-03 Thread Tim Michelsen

Hello,
is there any possibility in python to retrieve the system wide internet 
connection settings?


I would like to access the proxy settings stored in
Internet Explorer - Extras - Options - Connection - LAN settings.

This would later be used by urllib. My aim is not to bother the user 
with another place to set the proxy when being behind a corporate firewall.


Thanks in advance  regards,
Timmie

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


Re: [Tutor] import data (txt/csv) into list/array and manipulation

2008-11-10 Thread Tim Michelsen



filetype(2) The other file contains signal data in three columns, column one
is a unique identifier type int, and the other two columns contain two type
int values (genomic location reference values)
  ** import this as array/list

I want to map the location of filetype(2) with respect to filetype(1) and be
able to do averaging of signal if I align all filetype one objects.

Thanks



import numpy as np

data = np.loadtxt('file.csv', dtype='|S10')
col1 = date[0]
col2 = date[1].astype(int)
...

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


Re: [Tutor] Python to exe--how much work?

2008-06-26 Thread Tim Michelsen
  I've had some success generati ng .exe files using pyinstaller for a 
few
simple python programs i've written (less than 100 lines of code, that 
just use the os module).  How much harder will this be for longer code 
with more modules imported?

you may also try GUI2exe
http://xoomer.alice.it/infinity77/main/GUI2Exe.html

which builds on top of py2exe but does assist in setting all options.

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


Re: [Tutor] Open a directory in the default file manager

2008-05-19 Thread Tim Michelsen

Hi!



  is there any function/module that allows me to open a directory in the
  default file manager of a operating system?

On Windows you can use os.startfile().
On pure Unices there's no such thing as filetype associations
However, if you use a desktop environment, you can spawn xdg-open (from 
xdg-utils) from Python. This will autodetect gnome, kde and xfce and use 
their tools (gnome-open, kfmclient, exo-open).

I think on OS X/Darwin there's a similar utility called `open'.

You can use sys.platform to determine which system you're running on.

I wasn't able to start explorer with os.startfile()

I then used
subprocess.call(['explorer', my_directory])

And it works.

Kind regards,
Timmie

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


Re: [Tutor] converting all files in a directory with subprocess

2008-05-19 Thread Tim Michelsen

Hello,
just for the records:
below is some code that works

### convert all t2t docs in a directory.


#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import subprocess
import fnmatch

documentation_directory = './doc/'

for file in os.listdir(documentation_directory):
if fnmatch.fnmatch(file, '*.t2t'):

### assemble file name
filepath = documentation_directory+file

### run txt2tags
#subprocess.call(['txt2tags', '--target=html', '--toc', 
documentation_directory+file])

subprocess.call(['txt2tags', '--target=html', '--toc', filepath])

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


[Tutor] Open a directory in the default file manager

2008-05-15 Thread Tim Michelsen

Hello,
is there any function/module that allows me to open a directory in the 
default file manager of a operating system?


Here I a piece of code how to open a URL in the default webbrowser:

http://www.python.org/doc/lib/module-webbrowser.html

import webbrowser
myurl = 'http://www.python.org'
webbrowser.open_new_tab(myurl)


I just wanna do the same with a directory.

The function should open Explorer on Windows, Nautilus on Gnome, Thunar 
onn XFCE4, ...


Thanks for your help in advance.

Regards,
Timmie

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


[Tutor] converting all files in a directory with subprocess

2008-05-08 Thread Tim Michelsen

Hello,
I am working on a automatic documentation program to convert my txt2tags 
based documentations sources into HTMl files. I want to use txt2tags via 
command line.


Here's my code:

#

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import subprocess
import fnmatch

documentation_directory = './doc/'

for file in os.listdir(documentation_directory):
if fnmatch.fnmatch(file, '*.t2t'):
print file
subprocess.call('txt2tags', '-t html', '--toc')

# END 

When I run the script it exits with the following error message:

 START OUTPUT 
python ./make_documentation.py
index.t2t
Traceback (most recent call last):
  File ./make_documentation.py, line 12, in module
subprocess.call('txt2tags', '-t html', '--toc')
  File /usr/lib/python2.5/subprocess.py, line 444, in call
return Popen(*popenargs, **kwargs).wait()
  File /usr/lib/python2.5/subprocess.py, line 545, in __init__
raise TypeError(bufsize must be an integer)
TypeError: bufsize must be an integer
 END OUTPUT 

I am stuck here. Why would the script not let txt2tags convert every 
file in my directory?

like
txt2tags -t html --toc THEFILE

I already tried

subprocess.call('txt2tags', '-t html', '--toc', file)

But without success.

I'd appreciate any pointer here.

Thanks and regards,
Timmie

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


Re: [Tutor] Arguments ina separate file

2008-04-21 Thread Tim Michelsen
 I have a big list of arguments, which I would like to
 keep in a  separate file. How do I pass arguments that
 are in a  separate file?
do you mean like setting?

do something like this
write them in the file myargs.py


import myargs

call_my_function(myargs.argument1, myargs.argument2)

see also my recent thread on settings called
setting program configuration for all files and modules of a program

Regards,
Timmie

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


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

2008-04-15 Thread Tim Michelsen
 Another option is to have the config settiongs in a normal
 Python module and just import it. 
 
 I think that the cfg-files are much more readable for others.
 
 More readable than:
 
 # Section Heading
 variable = value
 
 It looks pretty easy to read to me! :-)
 
 If its very complex you can use dictionaries:
 
 SectionFoo = {
 firstName : theValue
 second  : anotherValue
 }
 
 Which is still pretty easy for the casual reader/maintainer 
 and allows access like:
 
 import myconfig
 foo2 = myconfig.SectionFoo['second']
This seems like reinventing what the ConfigParser mdoule [1] already does.

I think I will read the config file once and the provide the parameters 
with a settings.py module throughout the program and the modules.
Sounds like doing it twice.
But to my optinion Config Parser offers the following advantage:
- Readable
- All are strings = no strange 'mysetting' is needed.

Thanks for your help.

Kind regards,
Timmie

[1]http://docs.python.org/lib/module-ConfigParser.html

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


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

2008-04-15 Thread Tim Michelsen
 But to my optinion Config Parser offers the following advantage:
 - Readable
 - All are strings = no strange 'mysetting' is needed.
 I'm not sure what you mean. The Python variables and dictionary 
 is all strings too. mysetting is just a string...
 
 He means, with ConfigParser strings don't need to be quoted, giving 
 perhaps a cleaner and more friendly syntax.
Yes, Kent that's what I wanted to express.
Thanks for clarifying.
My target here are users that do not develop python.

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


Re: [Tutor] cut all decimal places with zeros

2008-04-15 Thread Tim Michelsen
 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.
No.
I tested with
n = 10.0
You code returns '1'

My code returns '10'

Here again:
### CODE ###
def cut_decimals(float):

input: floating number
output: number as string with zero decimals removed

#print float-int(float)
#print '%.4f' %float
if float-int(float) != 0:
number =  '%.4f' %float
number = number.replace('0.','X.')
number = number.replace('0','')
number = number.replace('X.','0.')
else:
number =  '%.0f' %float
return number
 END ###

Regards,
Timmie

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


[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 provides the calculation operations. This will 
help to expand the functionality at a later stage. I want to achieve 
this through splitting the code into different modules.
The problem is now that I would always have to write the configration 
file specific code in each module that uses the configration settings 
(see code below).

How can I provide the settings stored in the configuration file 
throughout my program to all functions without needing to initiate the 
ConfigParser object in each module?

I through of having a special module settings.py which I could use to 
read in the configuration from the file and then import this in each module.

Is there a more decent and elegant way?
What is the state of the art in storing and parsing configuraions in 
python programs?

Kind regards,
Timmie



# CODE #
import sys
import locale
import ConfigParser
import gettext


## Path to configuration file
configuration_file_name = './config/program_settings.cfg'# name of 
the configuration file

## read configuration from config file
try:
 program_config = ConfigParser.ConfigParser()
 program_config.readfp(open(configuration_file_name))
except IOError, (errno, strerror):
 error_msg_exception = _(I/O error(%s): %s) % (errno, strerror)
 error_msg_no_config = _(No configuration file with name ), 
configuration_file_name, _(found in the program directory. Please copy 
your configuration there. Values will be replaced by defaults.)
 print error_msg_exception
 print error_msg_no_config
 easygui.msgbox(error_msg_no_config)
 #pass

output = program_config.get('output', 'file_extension')
#

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


[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.'

### END 

I would like to have the m_format to be formatted like 2 and the 
n_format like 2.5679. How can I achive this?
A g with 2.4 should return 2.4 and not 2.4000.

Basically, I am looking for a way to eliminate the decimal places that 
are zero (0).

I tried this humble function before appling the formatting and it works 
well with the numbers:

### CODE ###
def cut_decimals(float):

input: floating number
output: number as string with zero decimals removed

#print float-int(float)
#print '%.4f' %float
if float-int(float) != 0:
number =  '%.4f' %float
number = number.replace('0.','X.')
number = number.replace('0','')
number = number.replace('X.','0.')
else:
number =  '%.0f' %float
return number

n = 2.0
m = 2.5678908
g = 2.4
h = 1.45
i = 0.67
numbers = [n, m, g, h, i]
for i in numbers:
i_f = cut_decimals(i)
print i_f

### END ###
### OUTPUT ###


  %run ./test_number.py
2
2.5679
2.4
1.45
0.67
### END ###

Is there any more efficient solution using string formatting only?

Thanks in adavance.

Kind regards,
Timmie

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


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 file is shared with a non python program, but if
 its all Python then that's a much simpler approach...
I think that the cfg-files are much more readable for others.

 PS.
 Why all the parens around the error strings in your code?
I am using gettext:

_ = gettest.gettest

Got this from the documentation.

Thanks for your reply!

Timmie


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


[Tutor] loading modules only when needed and PEP 008

2008-03-19 Thread Tim Michelsen
Hello fellow Pythonistas,
I have a question concerning import statements.

My code uses matplotlib to plot the results of my calculations.

Since I want to make this plotting functionality a optional feature I 
would like to import matplotlib only when needed because it takes a lot 
of time for a TKinter-GUI to start up. And this start-up time is even 
longer when matplotlib is imported.

I am still in doubt because PEP 008 [1] states that all imports should 
come right at the beginning of the code.

My current code goes something like:

import sys

import matplotlib

## 
## do some calcs
## ...
matplotlib.plot(mydata)

a optimized version would be:
import sys

plot_data = 'yes' # option: yes/no

if plot_data == 'yes':
import matplotlib
else:
pass

## 
## do some calcs
## ...
if plot_data == 'yes':
matplotlib.plot(mydata)
else:
pass

How would you handle such a case?
What is recommended in such a case?
Does anyone have experience with this?

Thanks for your suggestions in advance!

Kind regards,
Tim



[1] PEP 8 -- Style Guide for Python Code - 
http://www.python.org/dev/peps/pep-0008/

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


[Tutor] reading parts of a input string into different variables based on units.

2008-03-19 Thread Tim Michelsen
Hello,
I would like to read several parts of a string into different variables 
based on the (physical) units of the quantities.

Here's my testing code:
###
mystring = '2m 4cm 3mm' # can also be '1pound 30pence', ...
mylist = mystring.split( )
print mylist

first = mylist[0]
second = mylist[1]
third = mylist[2]

print first, first
print second, second
print third, third

m = 0
cm = 0
mm = 0
## first list item
if first.endswith(m,-1):
 m = first.strip(m)
elif first.endswith(cm,-2):
 cm = first.strip(cm)
elif first.endswith(mm,-2):
 mm = first.strip(mm)
else:
 print 'Wrong unit!'
## second list item
if second.endswith(m,-1):
 m = second.strip(m)
elif second.endswith(cm,-2):
 cm = second.strip(cm)
elif second.endswith(mm,-2):
 mm = second.strip(mm)
else:
 print 'Wrong unit!'
## third list item
if second.endswith(m,-1):
 m = second.strip(m)
elif second.endswith(cm,-2):
 cm = second.strip(cm)
elif second.endswith(mm,-2):
 mm = second.strip(mm)
else:
 print 'Wrong unit!'

print m, cm, mm
###

Well, I cannot get the meters assigned to the m variable, the 
centimeters to the cm variable and the milimeters to the mm variable. 
All units end with m and therefore my code confuses the strings I am 
looking for. I would always reassign the m variable.

I would be very grateful of someone could give me a point or hint how I 
read the quantites (read: numbers) into my variables m, cm, mm.

Thanks and kind regards,
Timmie

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


Re: [Tutor] loading modules only when needed and PEP 008

2008-03-19 Thread Tim Michelsen
 When I do this sort of thing I like
 to move my imports into my functions/methods. 
Would this then be compliant with the style recommendations?

  The 'main' code then
 conditionally calls the function/method.  All the code in the
 function safely assumes that the import has been done but code in the
 calling function assumes the import hasn't been done.
Yes, this should a the solution.


 And as we are talking about style, note that your else: pass isn't
 really necessary but it does make it explicitly clear that you are 
 choosing not to do anything if the plot_data isn't 'yes'. 
Ok, so I already got some style here, at least...

 Are those
  tabs you're using?  Four spaces are preferred, according to the
 style guide.
I always use 4 spaces. This sometimes leads to confusions when working 
with the same editor on text files that rely tabs but this is another 
issue...


Thanks very much for your fast response!

Kind regards,
Timmie

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


Re: [Tutor] reading parts of a input string into different variables based on units.

2008-03-19 Thread Tim Michelsen
Hello,
thank you for the fast reply!

 A regex would avoid that since it would detect an m
 as being diffrent to a cm or mm.
 
 Of course you will have to work out the right regex but that
 shouldn't be too difficult if you are sure you have a whitespace
 separator and a number followed by the unit string.
I will see whether I can get the right regex together. Ease for educated 
computer scientist but for me coming from a Non-Programmer background 
the rege still bears some fear... and a learning curve.

 Now you have a list of values for each unit, you just need
 to convert the string values to numeric and sum them or
 whatever else you need to do.
I will try to step forward and the send my results back.

Thanks and regards,
Timmie

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


Re: [Tutor] using os module on windows

2008-02-21 Thread Tim Michelsen
 Delete, then copy. Or use rsync instead of Python...

Yes, I ended up writing a small *.bat file that uses unison for 
sychronization.

I still do not understand why I got these permission errors when using 
the python script.

Thanks for the help.

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


[Tutor] send file/mail to imap

2007-12-28 Thread Tim Michelsen
Hello,
I have a mbox file locally on my notebook.

I would like to send this file to my IMAP account using python.

Does anyone know a module or tutorial which does this?

I tried
* IMAPClient 0.3 - http://pypi.python.org/pypi/IMAPClient/0.3
but it doesn't contain a send function.

Thanks in advance for any hints,
Timmie

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


Re: [Tutor] detecting a change in a iterable object (list, array, etc.)

2007-12-18 Thread Tim Michelsen
Hello,
 A list comprehension will work for this. If data is a list of triples of 
 (year, month, volume) then this will give you a list of the 1997 triples:
 
 data1997 = [ item for item in data if item[0]==1997 ]

I tried your code out (see below).

Here is the output:


[]
[]
[]
[]
[]
[1990, 0, 1, -18.0]
[1990, 0, 2, -0.5]
[1990, 0, 3, -14.0]
[1990, 0, 4, -21.0]

How do I avoid the []?

What whould be the easiest way to save this list (without the []) into a file
and append a newline after each row?

Thanks for your help in advance,
Timmie

Here's the code:
#!/usr/bin/env python
# currently used modules
import csv

# SOME VARIABLES
#~ stattion_name = 'Sosan'
input_file_name = '../data/filter_test_data.csv'
output_file_name = '../data/filter_test_data_result.csv'

# prepare files
input_file = open(input_file_name, 'r')
output_file = open(output_file_name ,'w')
header = uYear, Month, Day, Hour_of_day [h], values, \n
input_data = csv.reader(input_file, delimiter=';')

#~ skip the first rows
line1 = input_file.readline()
line2 = input_file.readline()

#~ write the header
output_file.write(header.encode('utf-8'))

counter = 0
value_col = 6
for line in input_data:
#~ print line
#~ year month day temp_3hr
year = int(line[1])
month = int(line[2])-1
day = int(line[3])
value = float(line[6])*0.5
compact_list = [year, month, day, value]
res_rows = [ item for item in compact_list if compact_list[0] == 1990 ]
print res_rows
input_file.close()
output_file.close()




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


Re: [Tutor] detecting a change in a iterable object (list, array, etc.)

2007-11-27 Thread Tim Michelsen
Hello,
 If you show us what you have done so far it would be easier to make
 suggestions.
The thing is that I am working a lot with time series data and need to write
criteria based filters for that data.
There's already a start in SciPy Time Series package:
http://www.scipy.org/SciPyPackages/TimeSeries
But it is still in early development.

Your suggestions are exactly what I was looking for. A kick into the right
direction...

I found itertools when writing my code for the last list items:
http://groups.google.com/group/comp.lang.python/browse_thread/thread/34c7398eec5a92cd/68f0aaef68e5ca0e?lnk=raot

I will keep you upodated it when I finshed investigating and incorporating your
tips.

Thanks so far,
Timmie

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


[Tutor] detecting a change in a iterable object (list, array, etc.)

2007-11-26 Thread Tim Michelsen
Hello,
would like to ask for your help on the following issue:
What procedure can I use to detect if there's a change when iterating 
over a list?

For instance if I want to extract the years 1997 and 1998 from the table 
below and save them into separate files?
How do I build the average only on the 1997-year values?
Or how do find out that there is three successive values 3*2 and 3*2 in 
the volume column?

I already tried a for-loop in connection with a last_value == current 
value comparison but wasn't successful at all.

Therefore, I highly appreaciate any hint or pointer!


Example data:

Yearmonth   volume
19971   2
19972   2
19973   2
19974   5
19975   2
19977   1
19981   2
19982   6
19983   3
19984   3
19985   3
19986   1

Thanks and kind regards,
Tim Michelsen

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


[Tutor] symbol encoding and processing problem

2007-10-16 Thread Tim Michelsen
Dear list,
I have encountered a problem with encoding of user input and variables.

I want to read in user defined coordinates as a string like: 121° 55' 5.55''
Furthermore I would like to extract the degrees (integer number before the  ° 
sign), the minutes (integer number before the  '  sign) and the seconds
(floating point number before the  ''  sign).

When reading and processing the degree part I get some errors:

Heres my test script:

 1 #!/usr/bin/env python
 2 # -*- coding: utf-8 -*-
 3 from easygui import easygui
 4 import sys
 5 #raw = sys.argv[1]
 6 raw = easygui.enterbox(message=Enter something., title=,
argDefaultText=20° 12' 33'')
 7 #unicode = unicode(raw)
 8 #conv = raw.encoding('latin-1')
 9 split = raw.split('°')
10 out = raw
11 print out
12 easygui.msgbox(out)

Here ist my output:

20° 12' 33''
Traceback (most recent call last):
  File C:\python24\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py,
line 310, in RunScript
exec codeObject in __main__.__dict__
  File D:\python\scripts\encoding-test.py, line 22, in ?
split = raw.split('°')
UnicodeDecodeError: 'ascii' codec can't decode byte 0xb0 in position 0: ordinal
not in range(128)
Traceback (most recent call last):
  File C:\python24\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py,
line 310, in RunScript
exec codeObject in __main__.__dict__
  File D:\python\scripts\encoding-test.py, line 22, in ?
split = raw.split('°')
UnicodeDecodeError: 'ascii' codec can't decode byte 0xb0 in position 0: ordinal
not in range(128)

Therefore my question:
* How can I split at the ° without getting a charater encoding error?
* How do I have to encode the °-symbol that it gets correctly displayed in the
Easygui msgbox at line 6?

Thanks inadvance for answering,
Timmie


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


Re: [Tutor] symbol encoding and processing problem

2007-10-16 Thread Tim Michelsen
 How do you get this output? The print is after the statement causing the 
 traceback. Are you showing the same code as you ran?
Yes.
I created this file in PythonWin and run it with IPython.

 It displays correctly for me (on MacOS X). Are you sure your source is 
 actually encoded in utf-8?
Not really.
The thing is that I am exchanging my files from Linux (Ubuntu with UTF-8
default) to Windows.
 What platform are you on?
Yesterday I run the code on windows.

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


Re: [Tutor] input file encoding

2007-09-11 Thread Tim Michelsen
 Not sure what you mean by standard encoding (is this an Ubuntu
 thing?) but essentially whenever you're pulling stuff into Python
As it was lined out by others I was printing to a linux terminal which 
had the encoding set to UTF-8.
Therefore and for further processing of the data I had to open it with 
the right encoding.


 In this case, assuming you have files in iso-8859-1, something
 like this:
 

 code
 import codecs
 
 filenames = ['a.txt', 'b.txt', 'c.txt']
 for filename in filenames:
f = codecs.open (filename, encoding=iso-8859-1)
This piece of code did the trick. After a short adaption I had exactly 
what I wanted to achive.


Thanks you for your help.

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


[Tutor] input file encoding

2007-09-10 Thread Tim Michelsen
Hello,
I want to process some files encoded in latin-1 (iso-8859-1) in my 
python script that I write on Ubuntu which has UTF-8 as standard encoding.

When I use the print lines_in_myfile is get some wired symbols.

How shold I read those files in or convert their encoding to utf-8?

Thanks in advance,
Tim

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


Re: [Tutor] Python Book Recommendations [Was:[Re: Security]]

2007-08-19 Thread Tim Michelsen
Hello,

 Univ of Toronto, Indiana Univ, and Caltech. Dr. Wilson wrote about it in
 the magazine of Sigma Xi:

 http://www.americanscientist.org/template/AssetDetail/assetid/48548

 It has moved around a lot. It's current official home is on scipy.org:

 http://www.swc.scipy.org/

 There are several links to older SWC URLs on python.org. None of them
 are in the wiki where they could be easily fixed, however.
 
 Chris, THANK YOU, especially for the link, http://www.swc.scipy.org/.
 
 My thanks also to Alan, Wesley, and bhaaluu. What a great list Tutor is!
Me too, I want to second Dick Moore and thank y'all for sending this 
out! How nice that the SWC gets updated and improved!

@Dick, as another noob, I wish you success in stepping into Python ;-)

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


Re: [Tutor] Python Book Recommendations [Was:[Re: Security]]

2007-08-16 Thread Tim Michelsen
Hey bhaaluu and list,

 Have you seen this site yet?
 
 http://osl.iu.edu/~lums/swc/
Many many thanks for this link.
Although it should be the most obvious to head to the source 
(python.org) I didn't go there.

The above mentioned tutorial seem to cover exactly what I need and where 
I want do dig deeper it gives valuable references and links for futher 
readings.
I'd recommend this to any non-programmer who likes to learn python to 
solve his real-life computer problems that arise in his/her science 
field of origin like earth/geo science, biology, physics or engineering.
Once I will have finished this tutorial I may decide whether I by 
another book or not.



 Another site that seems really helpful for scientists wanting
 to learn Python is:
 http://www.pasteur.fr/formation/infobio/python/
This one had already been mentioned on this thread, I guess.

Regards,
Timmie


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


Re: [Tutor] Python Book Recommendations [Was:[Re: Security]]

2007-08-15 Thread Tim Michelsen
Hello list,
thanks to everybody who shared their experience with books and their 
usefulness.

I think with regard to the other thread that passed lately:

Books with exercises and problems to solve - 
http://article.gmane.org/gmane.comp.python.tutor/42394

we must admit there are two type of learners:

* real programming beginners/novices who take Python to enter the world 
of programmin or need to program only to solve some specific problems 
that are arising in other areas of work like scientific data analysis, 
modelling or engineering

* computer professionals who are very familiar with programming and 
already know some lingos. They need a different learning approach than 
the first group.

I for instance belong to the first group. I need Python for effective 
data manipulation  analysis or program customatization/scripting within 
other programs, etc. I bought Python Scripting for Comuptional Science 
by H. Langtangen.
While this book adresses exctly my needs as far as the content and 
spcialization is concerned I want to start off learning with a book that 
helps me to pick up easier. Learning -- which is a auto-learning and 
free choice in my case -- should be fun! Therefore I am consindering to 
buy Python Programming for the Absolute Beginner.

Did anyone here use this book for leaning? Is it easy enough for a 
non-programmer while not being too light?

Kind regards,
Tim

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


[Tutor] FAQ [Was Re: Python Book Recommendations [Was:....]]

2007-08-14 Thread Tim Michelsen
Hello,
is there a FAQ for this list where we could put all these recommendations?

Thanks,
Timmie

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


Re: [Tutor] adapting a converter openoffice

2007-07-26 Thread Tim Michelsen
 When you say nothing happemed I assume you mean the script
 never terminated? 
Yes, you are right. it does not terminate and only blocks the screen.


As stated on the site the script needs some special parameters of 
Openoffice. Therefore, until I step further, I wrap it around a shell 
script that I will put in my PATH:

#!/bin/bash
###licence
##which licence applies for this script? If not changed it will be 
released under GPL:
#This shell script is free software; you can redistribute it and/or 
modify it under the terms of the GNU General Public License as published 
by the Free Software Foundation; either version 2 of the License, or (at 
your option) any later version.
#
#This shell script  is distributed in the hope that it will be useful, 
but WITHOUT ANY WARRANTY; without even the implied warranty of 
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
General Public License for more details.
#
#You should have received a copy of the GNU General Public License along 
with this shell script ; if not, write to the
#Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 
  02111-1307  USA
#or read the text online: http://www.gnu.org/licenses/gpl.txt
###script description
##convert from/to openoffice document formats using a script from
##http://www.artofsolving.com/opensource/pyodconverter
##see also: http://www.linux.com/articles/61713
#start OpenOffice as a service
soffice -headless -accept=socket,port=8100;urp;
#get variables
# @1 = SOURCE
# @2 = DESTINATION
#convert command
# /opt/local/pyodconverter $SOURCE $DESTINATION
cd /opt/local/pyodconverter/
python ./DocumentConverter.py $1 $2
exit

Maybe one day I will be able to do this in python using pyodconverter as 
a class...

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


[Tutor] adapting a converter openoffice

2007-07-26 Thread Tim Michelsen
Hello,
I am Python learning in an early stage.

I am currently trying to code a converter for openoffice based on 
PyODConverter:
http://www.artofsolving.com/opensource/pyodconverter

My goal is to be able to run my script from anywhere in the system (put 
it in Path) and then convert a file from/to openoffice formats to other 
formats such as doc/pdf etc.

My main problem is how to issue system commands and then run the above 
script.

PyODConverter needs OpenOffice.org to be running as a service which can 
be initiated through the following command on the command line (linux 
shell):
soffice -headless -accept=socket,port=8100;urp;

once the service is up and running the conversion process is really 
straight forward:
python DocumentConverter.py test.odt test.pdf
where DocumentConverter.py is the ready-to-use converter program 
downloadable at http://www.artofsolving.com/opensource/pyodconverter

I want to be able to convert the files anywhere without the need to 
start the OOo service seperately.

Therefore I tried to add this code on top of the original converter:

###get OOo service started first:
import os
code = os.system('soffice -headless -accept=socket,port=8100;urp;') # 
Just execute the command, return a success/fail code

when I execute this script nothing happens and I would have to cancel it.

Is there any way to start the OOo service from a python script?

Thanks in advance for your help!

Timmie

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