tips requested for a log-processing script

2006-11-05 Thread Jaap
Python ers,
As a relatively new user of Python I would like to ask your advice on 
the following script I want to create.

I have a logfile which contains records. All records have the same 
layout, and are stored in a CSV-format. Each record is (non-uniquely) 
identified by a date and a itemID. Each itemID can occur 0 or more times 
per month. The item contains a figure/amount which I need to sum per 
month and per itemID. I have already managed to separate the individual 
parts of each logfile-record by using the csv-module from Python 2.5. 
very simple indeed.

Apart from this I have a configuration file, which contains the list of 
itemID's i need to focus on per month. Not all itemID's are relevant for 
each month, but for example only every second or third month. All 
records in the logfile with other itemID's can be ignored. I have yet to 
define the format of this configuration file, but am thinking about a 0 
or 1 for each month, and then the itemID, like:
"1 0 0 1 0 0 1 0 0 1 0 0 123456" for a itemID 123456 which only needs 
consideration at first month of each quarter.

My question to this forum is: which data structure would you propose? 
The logfile is not very big (about 200k max, average 200k) so I assume I 
can store in internal memory/list?

How would you propose I tackle the filtering of relevant/non-relevant 
items from logfile? Would you propose I use a filter(func, list) for 
this task or is another thing better?

In the end I want to mail the outcome of my process, but this seems 
straitforward from the documentation I have found, although I must 
connect to an external SMTP-server.

Any tips, views, advice is highly appreciated!


Jaap

PS: when I load the logfile in a spreadsheet I can create a pivot table 
which does about the same ;-] but that is not what I want; the 
processing must be automated in the end with a periodic script which 
e-mails the summary of the keyfigure every month.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tips requested for a log-processing script

2006-11-06 Thread Jaap
Hendrik van Rooyen schreef:
> "Jaap" <[EMAIL PROTECTED]> wrote:
> 
> 
>> Python ers,
Thanks!
all your replies have been both to the point and helpfull for me.

You have proven both Python and it's community are open and welcoming to 
new users.

Jaap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: - E04 - Leadership! Google, Guido van Rossum, PSF

2006-01-02 Thread Jaap Spies
 is credited to persons higher in
>>the hierarchy and mistakes are the faults of research assistents or
>>students. Only if this system breaks down we see reports of "scientific
> 
> 
> Can you show that happening for Guido van Rossum, for example, or Greg
> Stein?  What "hierarchy" were they in, to enable them, as you're
> accusing, to take credit for accomplishments that are not their own, and
> deflect blame to poor maligned underlings?
> 
> You've made a very specific and insulting claim about Google hiring only
> people with long histories of backstabbing, and yet it appears that
> you're failing to substantiate it.  Hurling such accusations (ones which
> obviously must involve specific people, since the whole thread, as
> indicated by the subject, starts with Guido's working for Google)
> without being able to provide any substance is, in my strongly held
> opinion, quite reprehensible, and doesn't reflect well on you.
> 
> 
> 
>>However for *me* personally, because I am deserted by my government,
>>the university community, friends and family, and left to fend for
>>myself, there is no pressing need to keep up the facade so I can
>>finally see it for what it is.
>>
>>I hope this answers some of your questions about my position. Anyway, I
>>think its better to talk about positive things, like trying to convince
>>google to hire any and all people who can program irrespective of their
>>corruption history. 
> 
> 
> People who distinguish themselves as outstanding contributors to
> open-source projects can generally clear the "or equivalent" hurdle
> without difficulty.  Do you consider a history of such contributions to
> be a "corruption history" and evidence of "backstabbing", too?  To
> emerge as such an outstanding contributor, titles are irrelevant: all
> you need, besides willingness and ability to invest your time that way,
> are outstanding technical ability (particularly in design and coding,
> but testing and debugging are also very important, and so is a knack for
> writing good documentation -- one can become an "outstanding
> contributor" through many possible combinations of such skills) AND any
> of a wide range of suitable character and personality traits.
> 
> To focus on the latter: I would never want Google to hire somebody, no
> matter how great a programmer they might be, who can accuse, for
> example, Guido van Rossum, of having a "long history of backstabbing",
> without any substantial data to back up the accusation, just to vent
> their frustration at their personal situation.  You DID say that Google
> hires ONLY people with long histories of backstabbing, and by the very
> definition of the word "ONLY" this means you are accusing me, Guido,
> Greg, etc, etc, of having "long histories of backstabbing" -- and after
> hurling such insults, and providing NO specific data to support them,
> you're hallucinating that you can now switch "to talk about positive
> things"?!
> 
> One reason I'm so happy we've hired Guido is that, in addition to his
> technical excellence, he's just a great guy, wonderful to work with.
> Technical excellence is a necessary but not sufficient quality: one ALSO
> needs suitable combinations of character and personality, and Guido has
> them, in spades.  There is an enormous variation of personalities and
> character traits at Google (we DO value diversity!), but they all have
> in common the fact that they can combine into small, fluid teams which
> become even more productive than "the sum of their parts", because
> teammates LIKE AND RESPECT AND TRUST each other.  I do not see how
> somebody whose behavior included such unsubstantiated "backstabbing"
> accusations could be productive in this way.
> 
> 
> And, about the job-posting you liked better...:
> 
> 
>>Run by an engineer, this work environment is a meritocracy. You will be
> 
> 
> To me, "meritocracy" and "elitism" are close to being synonyms, in most
> contexts.  "Meritocracy" is defined somewhere on the net as:
> """
> A system of government whereby a particular standard of ability is used
> as the basis by which political leadership is determined or accrues to
> an existing elite.
> """
> Note the connection with "elite", which in turn gives us "elitism".  I
> do like "meritocracy" because it specifically mentions *ability*, but of
> course ability (including technical skill, which in turn is enhanced by
> appropriate experience, AND 'softer' character/personality issues) is
> what a successful firm bases its "elite" on (or tries to; if it fails,
> and hires people bereft of sufficient ability, it won't prosper long).
> 
> 
> Alex


That all been said. My recommandation: hire that man!

Jaap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Elliptic Curve Library

2006-12-23 Thread Jaap Spies
Mike Tammerman wrote:

> I need an elliptic curve library that can be used by python. I googled
> but couldn't find a one. I'll appreciate, if you could show me.
> 

You could look at http://sage.scipy.org/sage/
http://sage.scipy.org/sage/features.html

Jaap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python on Computation, Math and Statistics

2007-08-19 Thread Jaap Spies
W. Watson wrote:
> I would hope Python is doing a lot of standard computations beyond 
> arithmetic. Trig functions and more. Comments?

Try SAGE: http://www.sagemath.org/

Jaap


Permanents are here forever.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: from maple to python + numpy/scipy

2007-03-19 Thread Jaap Spies
Daniel Nogradi wrote:
> I'm just getting started with numpy/scipy and first would like to get
> a view of what it can do and what it can't. The main idea is to move
> from maple to python and the first thing that poped up is the fact
> that maple is very convenient for both formal manipulations and exact
> integer calculations. For instance if a matrix has integer entries and
> the eigenvalues are integers maple can find these exactly.
> 
> Can numpy/scipy do this? Or the eigenvalues will always be floating
> point numbers?

Have a look at SAGE (Software for Algebra and Geometry Experimentation)
http://www.sagemath.org/

Jaap

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Fortran vs Python - Newbie Question

2007-03-27 Thread Jaap Spies
Mark Morss wrote:

> 
> Maybe somebody reading this will be able to convince me to look again
> at Numpy/Scipy, but for the time being I will continue to do my
> serious numerical computation in Fortran.
> 

What I am missing in this discussion is a link to Pyrex to speed up
Python: Pyrex is almost Python with the speed of compiled C.
http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/

Pyrex is adapted in SAGE (Software for Algebra and Geometry 
Experimentation) as Sagex: http://modular.math.washington.edu/sage/

Jaap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Research-oriented Python mailing list?

2007-11-22 Thread Jaap Spies
Michael Tobis wrote:
> Perhaps what you are looking for is here:
> 
> http://www.scipy.org/Mailing_Lists
> 
> mt

Or here:

http://www.sagemath.org/
http://www.sagemath.org/lists.html

Jaap

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: convert pdf to png

2007-12-24 Thread Jaap Spies
Carl K wrote:
> I need to take the take the pdf output from reportlab and create a 
> preview image for a web page.  so png or something.  I am sure 
> ghostscript will be involved. I am guessing PIL or ImageMagic ?
> 
> all sugestions welcome.
> 

If it is a multi page pdf Imagemagick will do:

convert file.pdf page-%03d.png

Jaap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: convert pdf to png

2007-12-24 Thread Jaap Spies
Carl K wrote:
> Grant Edwards wrote:
>> On 2007-12-24, Carl K <[EMAIL PROTECTED]> wrote:
>>
>>>> If it is a multi page pdf Imagemagick will do:
>>>>
>>>> convert file.pdf page-%03d.png
>>> I need python code to do this.  It is going to be run on a
>>> someone else's shared host web server, security and
>>> performance is an issue.  So I would rather not run stuff via
>>> popen.
>>
>> Use subprocess.
>>
>> Trying to eliminate popen because of the overhead when running
>> ghostscript to render PDF (I assume convert uses gs?) is about
>> like trimming an elephants toenails to save weight.
>>
> 
> maybe, but I wouldn't be so sure.
> 
> currently the pdf is created in a python StringIO buffer and returned to 
> the browser;  so it never becomes a file.  using convert means I have to 
> first save it as a file, convert from file to file, read the file, 
> delete the 2 files. so 6 file operations where before there were none.  
> That may be more of a load than the ghostscript part.
> 
> Carl K

Are you clever and am I stupid? I did not read this in your original post!

Jaap

-- 
http://mail.python.org/mailman/listinfo/python-list


socket timeout error?

2006-04-17 Thread Jaap Spies
Hi,

Running Fedora Core 4: Python 2.4.3 and Python 2.4.1.
I'm getting:
IOError: [Errno socket error] (2, 'No such file or directory')
all the time.

Trying to track down this problem:

Python 2.4.1 (#1, May 16 2005, 15:19:29)
[GCC 4.0.0 20050512 (Red Hat 4.0.0-5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> import socket
 >>> socket.getdefaulttimeout()
 >>> import urllib
 >>> urllib.urlopen('http://www.python.org')
Traceback (most recent call last):
   File "", line 1, in ?
   File "urllib.py", line 77, in urlopen
 return opener.open(url)
   File "urllib.py", line 180, in open
 return getattr(self, name)(url)
   File "urllib.py", line 296, in open_http
 h.endheaders()
   File "/usr/lib/python2.4/httplib.py", line 794, in endheaders
 self._send_output()
   File "/usr/lib/python2.4/httplib.py", line 675, in _send_output
 self.send(msg)
   File "/usr/lib/python2.4/httplib.py", line 642, in send
 self.connect()
   File "/usr/lib/python2.4/httplib.py", line 610, in connect
 socket.SOCK_STREAM):
IOError: [Errno socket error] (2, 'No such file or directory')
 >>> socket.setdefaulttimeout(0.1)
 >>> socket.getdefaulttimeout()
0.10001
 >>> urllib.urlopen('http://www.python.org')
>>>> socket.setdefaulttimeout(0.01)
 >>> urllib.urlopen('http://www.python.org')
Traceback (most recent call last):
   File "", line 1, in ?
   File "urllib.py", line 77, in urlopen
 return opener.open(url)
   File "urllib.py", line 180, in open
 return getattr(self, name)(url)
   File "urllib.py", line 296, in open_http
 h.endheaders()
   File "/usr/lib/python2.4/httplib.py", line 794, in endheaders
 self._send_output()
   File "/usr/lib/python2.4/httplib.py", line 675, in _send_output
 self.send(msg)
   File "/usr/lib/python2.4/httplib.py", line 642, in send
 self.connect()
   File "/usr/lib/python2.4/httplib.py", line 626, in connect
 raise socket.error, msg
IOError: [Errno socket error] timed out
 >>> socket.setdefaulttimeout(0.05)
 >>> urllib.urlopen('http://www.python.org')
>>>>

Seems a timeout of 0.01 is to small and a timeout >= 0.05 is working.

What is the real problem here?

Jaap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Will Python on day replace MATLAB?????????????????????????????????????????????????????

2008-02-01 Thread Jaap Spies
Stef Mientki wrote:
> Blubaugh, David A. wrote:
>> To All,
>>
>>
>> I have been evaluating the python environment ever more closer.  I
>> believe I can interface python with a development environment known as
>> the ImpulseC environment.  The ImpulseC environment develops C to VHDL
>> for FPGA development. I would especially love to interface Python
>> with ImpulseC and the graphing capabilities of GNU Plot and SciPy in
>> order to recreate a VHDL development environment that will be just as
>> capable as a $50,000 dollar Matlab to VHDL toolbox.  This is also a part
>> of my Masters thesis.  Is anyone willing to help in this endeavor? 
>>   
> For all common math things SciPy can replace MatLab,
> with the main advantage that every library is open,
> so you're always be able to trace weird results (which was my great 
> frustation with MatLab).
> 
> If Scipy WILL replace MatLab is more a question of marketing than of 
> quality.

Have a look at Sage: http://www.sagemath.org/


Jaap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python for a matlab user

2008-02-02 Thread Jaap Spies
David Wang wrote:
> hello python users,
> 
> i use matlab in my daily research and some shell scripting as well
> (primarily for data analysis). i wonder how easy or difficult for a
> matlab user to pick up python? i also know Fortran but haven't used it
> for years.
> 
> thanks for your comments,
> d.
> 

Try Sage! Sage has it all! Sage is written (mainly) in Python.
Sage/Python is fun, easy to learn!

See: http://www.sagemath.org/

Jaap

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Combinatorics

2008-02-12 Thread Jaap Spies
Robert Dodier wrote:
> Cameron Laird wrote:
> 
>> Should combinatorics be part of the standard library?  That's
>> an aesthetic-pragmatic question I don't feel competent to
>> answer; I look to timbot and Guido and so on for judgment there.
>> It does occur to me, though, that even more widely applicable
>> than the combinatorics module of Mathematica (if only because of
>> its licensing) might be such resources as
> [...]
> 
> Well, since Mathematica has been mentioned, I'll go ahead and
> mention Maxima as well. Maxima is an open source (GPL) symbolic
> computation system, which includes some functions for
> combinatorics, among many other things. The relevant code is:
> http://maxima.cvs.sourceforge.net/maxima/maxima/src/nset.lisp
> (Oh, btw Maxima is written in Lisp.) The relevant documentation:
> http://maxima.sourceforge.net/docs/manual/en/maxima_37.html
> 
> Sage can presumably access Maxima's combinatoric functions
> (since Sage bundles Maxima along with other programs).
> I don't know if there are combinatoric functions from other
> packages in Sage.

There is a native combinatorics module in Sage. See:
http://www.sagemath.org/doc/html/ref/node181.html

Sage: http://www.sagemath.org/


Jaap




> 
> FWIW
> 
> Robert Dodier
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [OT] Looking for a Python Program/Tool That Will Add Line Numbers to a txt File

2008-02-14 Thread Jaap Spies
Gabriel Genellina wrote:
> En Thu, 14 Feb 2008 04:54:56 -0200, W. Watson <[EMAIL PROTECTED]> 
> escribió:
> 
>> See Subject. It's a simple txt file, each line is a Python stmt, but I 
>> need
>> up to four digits added to each line with a space between the number 
>> field
>> and the text. Perhaps someone has already done this or there's a 
>> source on
>> the web for it. I'm not yet into files with Python. A sudden need has 
>> burst
>> upon me. I'm using Win XP.
> 
> This command should suffice - but you must first find a working CP/M 
> system to use it:
> 
> C>PIP [N] NEW.PY=OLD.PY
> 
> (Sorry - just a a nostalgic flash!)
> 

Wow! You remembered this. Good old PIP!

Jaap

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using Python for programming algorithms

2008-05-18 Thread Jaap Spies

Vicent Giner wrote:

Hello.

I am new to Python. It seems a very interesting language to me. Its
simplicity is very attractive.

However, it is usually said that Python is not a compiled but
interpreted programming language —I mean, it is not like C, in that
sense.

I am working on my PhD Thesis, which is about Operations Research,
heuristic algorithms, etc., and I am considering the possibility of
programming all my algorithms in Python.

The usual alternative is C, but I like Python more.

The main drawbacks I see to using Python are these:

* As far as I understand, the fact that Python is not a compiled
language makes it slower than C, when performing huge amounts of
computations within an algorithm or program.

* I don't know how likely it is to find libraries in Python related to
my research field.

* I know Python is a "serious" and mature programming language, of
course. But I do not know if it is seen as "just funny" in a research
context. Is Python considered as a good programming language for
implementing Operations Research algorithms, such as heuristics and
other soft-computing algorithms?



You definitely should take a look at Sage: http://www.sagemath.org/

This may offer all you need, based on Python integrating a lot of
other programs!

Jaap
--
http://mail.python.org/mailman/listinfo/python-list


Re: Using Python for programming algorithms

2008-05-19 Thread Jaap Spies

Vicent Giner wrote:

Thank you very much for all the answers I've got.

As far as I have understood, Python can be a good alternative, or, at
least, a reasonable choice.

I intend to design new algorithms for a kind of Optimization problems,
and then I have to implement them and show/prove that they are good
enough, in terms of effectiveness (quality of the solution that the
algorithm is able to find, for some given "difficult" problems), and
not mainly in terms of efficiency (time to find the solution).

I mean, in order to prove that my algorithms are "good", I have to
compare them with the results given by other algorithms, in terms of
how much better is the solution given by my proposal, in front of the
previous ones. Only comparatives in terms of "number of iterations",
and not "time to find the solution", can be done (I think).



Here you find good company in the Sage developers community!

Jaap



And I also realize, from your posted answers, that the point is doing
a good programming work, and that I will have to look very carefully
at all those packages and resources you have mentioned, to do a good
work at Python.

Any other suggestion will be welcomed.:-)

Thank you very much again!

--
Vicent

--
http://mail.python.org/mailman/listinfo/python-list


Re: Mathematical Python Library

2008-04-07 Thread Jaap Spies
Cameron Laird wrote:
> In article <[EMAIL PROTECTED]>,
> Dennis Lee Bieber  <[EMAIL PROTECTED]> wrote:
>> On Mon, 7 Apr 2008 09:05:57 -0700 (PDT), mc <[EMAIL PROTECTED]>
>> declaimed the following in comp.lang.python:
>>
>>> I'm looking for a library which can do mathematical stuff like
>>> solving  equations. Or calculation the nulls of a function and so on.
>>> Does anyone know one?
>>>
>>  Other than coding some serial/USB interface to an HP50g...
>>
>>  Maybe SAGE? 
>>  sympy?
>>
>> http://www.google.com/search?hl=en&q=python+computer+algebra+system&btnG=Google+Search
>   .
>   .
>   .
> While there are in fact several possible approaches to symbolic mani-
> pulation of "mathematical stuff" in Python, I STRONGLY recommend that
> beginners in the area look into SAGE http://www.sagemath.org/ >, 
> already mentioned above by Dennis.  SAGE is life-altering software, for
> those with a life focused on mathematics or related science or
> engineering.

+1

Jaap

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wrapping C functions in python

2008-04-10 Thread Jaap Spies
Paul Anton Letnes wrote:
> Hi, and thanks.
> 
> 
> However, being a newbie, I now have to ask: What is SWIG? I have heard 
> the name before, but haven't understood what it is, why I need it, or 
> similar. Could you please supply some hints?
> 
[...]
>>>
>>> I am a "scientific" user of Python, and hence have to write some 
>>> performance
>>> critical algorithms. Right now, I am learning Python, so this is a 
>>> "newbie"
>>> question.
>>>
>>> I would like to wrap some heavy C functions inside Python, 
>>> specifically a
>>> wavelet transform. I am beginning to become aquainted with the functions
>>> PyArg_ParseTuple() and Py_BuildValue(). However, I am unable to 
>>> figure out
>>> how to pass Python list -> C function or C array -> return value in 
>>> Python.
>>> I manage to build and run the C function, print to screen, pass 
>>> string as
>>> argument, return an int, etc. The thing which is missing is the magic
>>> array/list...
>>>
>>>
>>> Thanks in advance! I fart in your general direction.
>>> Paul.

Maybe you should have a look at Cython:

http://www.cython.org/

and Sage:

http://www.sagemath.org/

Jaap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: SWIGing problem

2006-03-23 Thread Jaap Spies
Robert Kern wrote:
> Tommy Grav wrote:
> 
>>This might not be the venue to ask this but I do not know where else to
>>turn. 
>>I am trying to install a package that is swig'ed from some C code. 
>>Unfortunately the readme file isn't to informative.  Does anyone
>>know which libraries to link to to remove the undefined symbols
>>below?
>>
>>[EMAIL PROTECTED] Python/pynovas -> ld -dynamic novas_wrap.o libnovas.a -lm
>>-lpython -o _novas.so
>>ld: Undefined symbols:
>>_fprintf$LDBLStub
>>_printf$LDBLStub
>>dyld_stub_binding_helper
>>restFP
>>saveFP
> 
> 
> Ouch! Are they really not using distutils to build the extension modules? Even
> when you fix the specific issue above (if you're on OS X, add -lcc_dynamic to
> the link line; otherwise, I don't know), you're still probably going to have
> other problems. distutils knows how to build Python extensions modules. The
> pynovas Makefile doesn't.
> 

I did not use distutils, because I do not know how :-)! Maybe in the 
next release of PyNOVAS.

Jaap
-- 
http://mail.python.org/mailman/listinfo/python-list


timezones

2019-02-07 Thread Jaap van Wingerde
I made a small script to practise with timezones:

#!/usr/bin/env python3
# -*- coding: utf_8 -*-
from datetime import datetime, timedelta
from pytz import timezone
import pytz
amsterdam_datetime = datetime(2018, 12, 17, 11, 31, 26,
tzinfo=timezone('Europe/Amsterdam'))
print(amsterdam_datetime)
utc_datetime = amsterdam_datetime.astimezone(pytz.utc)
print(utc_datetime)
amsterdam_datetime = datetime(2018, 6, 17, 11, 31, 26,
tzinfo=timezone('Europe/Amsterdam'))
print(amsterdam_datetime)
utc_datetime = amsterdam_datetime.astimezone(pytz.utc)
print(utc_datetime)

The output of the script is:
2018-12-17 11:31:26+00:20
2018-12-17 11:11:26+00:00
2018-06-17 11:31:26+00:20
2018-06-17 11:11:26+00:00

I respected:
2018-12-17 11:31:26+01:00
2018-12-17 10:31:26+00:00
2018-06-17 11:31:26+02:00
2018-06-17 09:31:26+00:00

I need this functionality for adjusting wrong timestamps in Android
JPG-images as the 'Exif.GPSInfo.GPSTimeStamp' and
'Exif.GPSInfo.GPSDateStamp' are missing.

Why I get this unrespected results?

Kind regards,
Jaap.


-- 

Jaap van Wingerde
e-mail: [email protected]

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: timezones

2019-02-08 Thread Jaap van Wingerde
The blog of Paul Gansele [1] made me trying an other approach.

#!/usr/bin/env python3
# -*- coding: utf_8 -*-
### tested with python3.5
from datetime import datetime, timedelta, timezone
from dateutil import tz
amsterdam = tz.gettz('Europe/Amsterdam')
utc = tz.gettz('utc')
amsterdam_datetime = datetime(2018, 12, 17, 11, 31, 26,
tzinfo=amsterdam) print(amsterdam_datetime)
tuple = amsterdam_datetime.utctimetuple()
utc_datetime = datetime(tuple[0], tuple[1], tuple[2], tuple[3],
tuple[4], tuple[5]) print(utc_datetime)
amsterdam_datetime = datetime(2018, 6, 17, 11, 31, 26, tzinfo=amsterdam)
print(amsterdam_datetime)
tuple = amsterdam_datetime.utctimetuple()
utc_datetime = datetime(tuple[0], tuple[1], tuple[2], tuple[3],
tuple[4], tuple[5]) print(utc_datetime)

Output:
2018-12-17 11:31:26+01:00
2018-12-17 10:31:26
2018-06-17 11:31:26+02:00
2018-06-17 09:31:26

[1]
pytz: The Fastest Footgun in the West
2018-03-19
https://blog.ganssle.io/articles/2018/03/pytz-fastest-footgun.html


Op 2019-02-07T17:56:21+ schreef David Raymond
 in bericht
,
inzake:  het volgende.

> I'd say if the documentation mentions it, but doesn't say why, then
> we're not gonna be able to do much better for you as far as "why"
> goes.
> 
> http://pytz.sourceforge.net/
> 
> "Unfortunately using the tzinfo argument of the standard datetime
> constructors "does not work" with pytz for many timezones."
> 
> But it looks like they suggest something along the lines of...
> 
> timezone('Europe/Amsterdam').localize(datetime(2018, 12, 17, 11, 31,
> 26))
> 
> 
> From the examples on
> http://pytz.sourceforge.net/#problems-with-localtime ...
> 
> >>> eastern = timezone('US/Eastern')
> >>> fmt = '%Y-%m-%d %H:%M:%S %Z%z'
> >>> loc_dt = datetime(2002, 10, 27, 1, 30, 00)
> >>> est_dt = eastern.localize(loc_dt, is_dst=True)
> >>> edt_dt = eastern.localize(loc_dt, is_dst=False)
> >>> print(est_dt.strftime(fmt) + ' / ' + edt_dt.strftime(fmt))  
> 2002-10-27 01:30:00 EDT-0400 / 2002-10-27 01:30:00 EST-0500
> 
> 
> Browse through their examples and see if you can find something
> similar that works for you.
> 
> 
> -Original Message-
> From: Python-list
> [mailto:[email protected]] On
> Behalf Of Jaap van Wingerde Sent: Wednesday, February 06, 2019 9:27
> AM To: [email protected] Subject: timezones
> 
> I made a small script to practise with timezones:
> 
> #!/usr/bin/env python3
> # -*- coding: utf_8 -*-
> from datetime import datetime, timedelta
> from pytz import timezone
> import pytz
> amsterdam_datetime = datetime(2018, 12, 17, 11, 31, 26,
> tzinfo=timezone('Europe/Amsterdam'))
> print(amsterdam_datetime)
> utc_datetime = amsterdam_datetime.astimezone(pytz.utc)
> print(utc_datetime)
> amsterdam_datetime = datetime(2018, 6, 17, 11, 31, 26,
> tzinfo=timezone('Europe/Amsterdam'))
> print(amsterdam_datetime)
> utc_datetime = amsterdam_datetime.astimezone(pytz.utc)
> print(utc_datetime)
> 
> The output of the script is:
> 2018-12-17 11:31:26+00:20
> 2018-12-17 11:11:26+00:00
> 2018-06-17 11:31:26+00:20
> 2018-06-17 11:11:26+00:00
> 
> I respected:
> 2018-12-17 11:31:26+01:00
> 2018-12-17 10:31:26+00:00
> 2018-06-17 11:31:26+02:00
> 2018-06-17 09:31:26+00:00
> 
> I need this functionality for adjusting wrong timestamps in Android
> JPG-images as the 'Exif.GPSInfo.GPSTimeStamp' and
> 'Exif.GPSInfo.GPSDateStamp' are missing.
> 
> Why I get this unrespected results?
> 
> Kind regards,
> Jaap.
-- 
https://mail.python.org/mailman/listinfo/python-list


modification time in Python - Django: datetime != datetime :-(

2014-03-03 Thread Jaap van Wingerde
Django views.py:
...
pwd = os.path.dirname(os.path.realpath(__file__ ))
home_lastmod =  
strftime('%Y-%m-%dT%H:%m:%SZ',gmtime(os.path.getmtime(pwd+'/templates/art_index.html')))
...

The template gives a wrong modification time: "2014-03-02T19:03:55Z".

...
jaap@liakoster:~$ python
Python 2.7.3 (default, Jan  2 2013, 13:56:14) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os, time
>>> from time import
>>> gmtime
>>> time.strftime('%Y-%m-%dT%H:%m:%SZ',gmtime(os.path.getmtime('/var/django/test2/art/templates/art_index.html')))
>>>   
'2014-03-02T19:03:55Z'
>>> quit()  
jaap@liakoster:~$ ls --full-time /var/django/test2/art/templates/art_index.html
-rwxrwx--- 1 lia www-data 2456 2014-03-02 19:16:55.568139590 + 
/var/django/test2/art/templates/art_index.html
jaap@liakoster:~$ 
...

ls gives the right modification time. What is wrong?

...
jaap@liakoster:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description:Debian GNU/Linux 7.4 (wheezy)
Release:7.4
Codename:   wheezy
jaap@liakoster:~$ uname -a
Linux liakoster.shrl.nl 3.2.0-4-amd64 #1 SMP Debian 3.2.46-1+deb7u1 x86_64 
GNU/Linux
jaap@liakoster:~$ 
...

-- 
Jaap van Wingerde
e-mail: [email protected]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: modification time in Python - Django: datetime != datetime :-(

2014-03-03 Thread Jaap van Wingerde
Op  schreef Chris Angelico  
in bericht :

> See if ls is actually giving you ctime rather than mtime - compare the
> results if you ask for os.path.getctime.

jaap@liakoster:~$ python
Python 2.7.3 (default, Jan  2 2013, 13:56:14) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os, time
>>> from time import gmtime
>>> time.strftime('%Y-%m-%dT%H:%m:%SZ',gmtime(os.path.getmtime('/var/django/test2/art/templates/art_index.html')))
'2014-03-02T19:03:55Z'
>>> time.strftime('%Y-%m-%dT%H:%m:%SZ',gmtime(os.path.getctime('/var/django/test2/art/templates/art_index.html')))
'2014-03-02T19:03:55Z'
>>> quit()
jaap@liakoster:~$ ls --full-time /var/django/test2/art/templates/art_index.html
-rwxrwx--- 1 lia www-data 2456 2014-03-02 19:16:55.568139590 + 
/var/django/test2/art/templates/art_index.html
jaap@liakoster:~$ 

ls is giving me the modified time.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: modification time in Python - Django: datetime != datetime :-(

2014-03-04 Thread Jaap van Wingerde
Op 2014-03-03T12:22:48 UTC schreef donarb  in het
bericht , ID: <[email protected]> het 
volgende. 

> You're using the months format '%m' when you should be using minutes
> '%M'.

Arrgh: stupid error (snik).

p 2014-03-04T08:11:46 UTC schreef Chris Angelico  in
het bericht , ID: 

het volgende. 

> Heh! I didn't even notice that. When I tested it, I didn't use
> strftime at all, just looked at gmtime's output.

Op 2014-03-04T08:06:21 UTC schreef Ben Finney  in 
het bericht , ID: 
<[email protected]> het volgende.

> You're using ‘gmtime’ to display the Python datetime value, but ‘ls’
> will display the time in the local timezone. Do you have a strange
> timezone set?

I only use UTC.

Thanks

The view.py is now as follows.

...
home_lastmod = 
strftime('%Y-%m-%dT%H:%M:%SZ',gmtime(os.path.getmtime(os.path.dirname(os.path.realpath(__file__
 ))+'/templates/art_index.html')))
...

-- 

Jaap van Wingerde
e-mail: [email protected]

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PHP like documentation?

2009-02-15 Thread Jaap van Wingerde

Pavan Mishra wrote:

I was wondering if I can use python documentation source
(reStructuredText) and restructure it along the lines of PHP
documentation. Allowing users to add comments, improving search etc.
I was thinking if it would be useful.


Very good idea!



--
Jaap van Wingerde
e-mail: [email protected]
web: http://jaap.vanwingerde.net/
--
http://mail.python.org/mailman/listinfo/python-list


TypeError: descriptor 'replace' requires a 'str' object but received a 'unicode'

2009-02-21 Thread Jaap van Wingerde

# -*- coding: utf_8 -*-
Omschrijving = u'priv? assuranti?n' # string from a bank.csv
Omschrijving = str.replace(Omschrijving, "priv?", 'privé')
Omschrijving = str.replace(Omschrijving, "Assuranti?n", 'Assurantiën')
print Omschrijving

When I run this script I get the following message.

"Traceback (most recent call last):
  File "/home/jaap/Desktop/unicode.py", line 3, in 
Omschrijving = str.replace(Omschrijving, "priv?", 'priv�')
TypeError: descriptor 'replace' requires a 'str' object but received a 
'unicode'"


How can I solve this?




--
Jaap van Wingerde
e-mail: [email protected]
web: http://jaap.vanwingerde.net/
--
http://mail.python.org/mailman/listinfo/python-list


ordinal not in range

2009-02-21 Thread Jaap van Wingerde

Stefan Behnel wrote:

Omschrijving = Omschrijving.replace("priv?", 'privé')


I Thank you, this works now, but I get a new error message.


import codecs
file = "postbank.csv"
output = "%s.eb" % file
outfile = codecs.open(output, "w", "utf_8")
Omschrijving = u'priv? assuranti?n' # string from postbank.csv
Omschrijving = Omschrijving.replace("priv?", 'privé')
Omschrijving = Omschrijving.replace("Assuranti?n", 'Assurantiën')
outfile.write (Omschrijving)

"Traceback (most recent call last):
  File "/home/jaap/Desktop/unicode.py", line 9, in 
outfile.write (Omschrijving)
  File "/usr/lib/python2.5/codecs.py", line 638, in write
return self.writer.write(data)
  File "/usr/lib/python2.5/codecs.py", line 303, in write
data, consumed = self.encode(object, self.errors)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 4: 
ordinal not in range(128)"






--
http://mail.python.org/mailman/listinfo/python-list


Re: ordinal not in range

2009-02-21 Thread Jaap van Wingerde

Stefan Behnel wrote:

Omschrijving = Omschrijving.replace(u"priv?", u'privé')
(mind the u"...")
outfile = codecs.open(output, "wb", encoding="UTF-8")
(mind the "wb" for 'write binary/bytes')

It works now!


Looks like you'd be happier with Python 3.0, BTW...

Python 3 is not in Debian Lenny.

With your help I made my first Python-script. This script saves me from
hours dumb work.

Thanks a lot!!




--
Jaap van Wingerde
e-mail: [email protected]


--
http://mail.python.org/mailman/listinfo/python-list


Re: ordinal not in range

2009-03-02 Thread Jaap van Wingerde
Stefan Behnel wrote:
>> Jaap van Wingerde wrote:
>> outfile = codecs.open(output, "w", "utf_8")
> I guess you mixed up the case here.
> Does this help?
> outfile = codecs.open(output, "wb", encoding="UTF-8")

According to the Python "Codec registry an base classes"
<http://www.python.org/doc/2.6/library/codecs.html> "U8", "UTF", and
"utf8" are aliases and is the codec: utf_8.

Jaap.



-- 
Jaap van Wingerde
e-mail: [email protected]
web: http://jaap.vanwingerde.net/

--
http://mail.python.org/mailman/listinfo/python-list


Re: Python magazine

2010-03-29 Thread Jaap van Wingerde
On 29 mrt, 13:13, Pasi Oja-Nisula  wrote:
> Python magazine web site says this:
> "So, sit back and relax - enjoy your holidays, and come see us again on
> January 26th, when the new  PyMag will launch."


-- 
http://mail.python.org/mailman/listinfo/python-list