Usage of PyDateTime_FromTimestamp

2011-08-30 Thread Andreas
Hi,

I'm working on a c-extension of python and want to create an instance of
python datetime object with a unix timestamp in c.

On the documentation site ( http://docs.python.org/c-api/datetime.html )
I found the function PyDateTime_FromTimestamp() which returns a new
reference based on an input parameter.

The description is as follows: Create and return a new datetime.datetime
object given an argument tuple suitable for passing to
datetime.datetime.fromtimestamp().

I tried out to call the function with a PyFloat_Object but the function
always returns NULL (even if I simply put in 0).

Does somebody have an example how I have to call the function or can
give a hint what kind of parameter tuple is required to get it work?

Thanks!

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


Re: Usage of PyDateTime_FromTimestamp

2011-08-30 Thread Andreas
Am 30.08.2011 23:49, schrieb MRAB:

> The key phrase is "argument tuple". The arguments passed to a Python
> call are always a tuple, not PyFloat_Object.
> 
> You can build a tuple from the PyFloat_Object using:
> 
> Py_BuildValue("(O)", float_object)
> 
> The "(O)" says to build a tuple ("(...)") containing a single object
> ("O").

Thank you very much! That solved my problem.
Here the full working example:

static double doubleValue = 1314761451;
PyObject *floatObj = NULL;
PyObject *timeTuple = NULL;
PyObject *dateTime = NULL;

floatObj = PyFloat_FromDouble(doubleValue);
timeTuple = Py_BuildValue("(O)", floatObj);
dateTime = PyDateTime_FromTimestamp(timeTuple);




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


Re: HTTPSConnection script fails, but only on some servers (long)

2005-04-13 Thread andreas
Well HTTPSConnection does not support proxies. (HTTP/CONNECT + switch to HTTPS)

And it hasn't ever. Although the code seems to make sense there is
no support for handling that switch. Probably a good thing to complain
about (file a new bug report).

In the meantime you should take a look a cURL and pycurl, which do support
all kind of more extreme HTTP (FTP, etc.) handling, like using https over
an proxy.

Andreas

On Tue, Apr 12, 2005 at 03:37:33AM -0400, Steve Holden wrote:
> Paul Winkler wrote:
> >This is driving me up the wall... any help would be MUCH appreciated.
> >I have a module that I've whittled down into a 65-line script in
> >an attempt to isolate the cause of the problem.
> >
> >(Real domain names have been removed in everything below.)
> >
> >SYNOPSIS:
> >
> >I have 2 target servers, at https://A.com and https://B.com.
> >I have 2 clients, wget and my python script.
> >Both clients are sending GET requests with exactly the
> >same urls, parameters, and auth info.
> >
> >wget works fine with both servers.
> >The python script works with server A, but NOT with server B.
> >On Server B, it provoked a "Bad Gateway" error from Apache.
> >In other words, the problem seems to depend on both the client
> >and the server. Joy.
> >
> >Logs on server B show malformed URLs ONLY when the client
> >is my python script, which suggests the script is broken...
> >but logs on server A show no such problem, which suggests
> >the problem is elsewhere.
> >
> >DETAILS
> >
> >Note, the module was originally written for the express
> >purpose of working with B.com;  A.com was added as a point of reference
> >to convince myself that the script was not totally insane.
> >Likewise, wget was tried when I wanted to see if it might be
> >a client problem.
> >
> >Note the servers are running different software and return different
> >headers. wget -S shows this when it (successfully) hits url A:
> >
> > 1 HTTP/1.1 200 OK
> > 2 Date: Tue, 12 Apr 2005 05:23:54 GMT
> > 3 Server: Zope/(unreleased version, python 2.3.3, linux2) ZServer/1.1
> > 4 Content-Length: 37471
> > 5 Etag:
> > 6 Content-Type: text/html;charset=iso-8859-1
> > 7 X-Cache: MISS from XXX.com
> > 8 Keep-Alive: timeout=15, max=100
> > 9 Connection: Keep-Alive
> >
> >... and this when it (successfully) hits url B:
> >
> > 1 HTTP/1.1 200 OK
> > 2 Date: Tue, 12 Apr 2005 04:51:30 GMT
> > 3 Server: Jetty/4.2.9 (Linux/2.4.26-g2-r5-cti i386 java/1.4.2_03)
> > 4 Via: 1.0 XXX.com
> > 5 Content-Length: 0
> > 6 Connection: close
> > 7 Content-Type: text/plain
> >
> >Only things notable to me, apart from the servers are the "Via:" and
> >"Connection:" headers. Also the "Content-Length: 0" from B is odd, but
> >that doesn't seem to be a problem when the client is wget.
> >
> >Sadly I don't grok HTTP well enough to spot anything really
> >suspicious.
> >
> >The apache ssl request log on server B is very interesting.
> >When my script hits it, the request logged is like:
> >
> >A.com - - [01/Apr/2005:17:04:46 -0500] "GET
> >https://A.com/SkinServlet/zopeskin?action=updateSkinId&facilityId=1466&skinId=406
> >HTTP/1.1" 502 351
> >
> >... which apart from the 502, I thought reasonable until I realized
> >there's
> >not supposed to be a protocol or domain in there at all.  So this is
> >clearly
> >wrong. When the client is wget, the log shows something more sensible
> >like:
> >
> >A.com - - [01/Apr/2005:17:11:04 -0500] "GET
> >/SkinServlet/zopeskin?action=updateSkinId&facilityId=1466&skinId=406
> >HTTP/1.0" 200 -
> >
> >... which looks identical except for not including the spurious
> >protocol and domain, and the response looks as expected (200 with size
> >0).
> >
> >So, that log appears to be strong evidence that the problem is in my
> >client
> >script, right?  The failing request is coming in with some bad crap in
> >the path, which Jboss can't handle so it barfs and Apache responds with
> >
> >Bad Gateway.  Right?
> >
> >So why does the same exact client code work when hitting server B??
> >No extra gunk in the logs there. AFAICT there is nothing in the script
> >that could lead to such an odd request only on server A.
> >
> >
> >THE SCRIPT
> >
> >#!/usr/bin/python2.3
> >
> >from httplib import HTTPSConnection
> >from urllib import urlencode
> >import re
>

Re: delete will assure file is deleted?

2005-04-26 Thread andreas
On Tue, Apr 26, 2005 at 03:13:20PM -0400, Jeremy Bowers wrote:
> On Tue, 26 Apr 2005 03:40:16 -0700, [EMAIL PROTECTED] wrote:
> 
> > Hello Mike,
> > I have to know this topic otherwise my program has to check whether the
> > file / files are already deleted and this is a little bit messy.
> 
> I would be fairly confident in asserting that assuming the file is there,
> you have permissions, etc., basically that the call succeeds, that the
> file will be gone.
Not exactly. The system call is called remove not by accident. It's not
called delete. So for example if you have a file with multiple names (so called
hard links) the file will not be gone after os.remove('file')

> 
> os.remove, as the module name implies, tells the OS to do something. I
> would consider an OS that returned from a "remove" call, but still let you
> access that file, highly broken. 
Well, it has been the normal semantics with Unix for decades. Actually it's
the normal way to create temporary files that will be cleanuped when the program
exits:
f = open("temp")
os.remove("temp")
# now use f

f.close() # frees the temporary file
sys.exit(0) # exit is an implicit close too.

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


Problem compiling an extension with MS Visual C++ Toolkit 2003

2005-12-31 Thread Andreas
Extension:
---
pyshapelib 0.3 with Python 2.4

Problem:
-
D:\Python24\Lib\site-packages\shapelib\setup>pytest.py
Traceback (most recent call last):
  File "D:\Python24\Lib\site-packages\shapelib\setup\pytest.py", line
1, in ?
import shapelib, dbflib, shptree
  File "D:\Python24\Lib\site-packages\shapelib\setup\shapelib.py", line
2, in ?
import shapelibc
ImportError: DLL load failed: Das angegebene Modul wurde nicht
gefunden.
Windows Message: MSVCR80.dll not found.

Informations:
--
.NET Framework runtime and associated files are installed.

.NET Framework SDK installed.

Windows SDK installed.

Visual C++ Toolkit 2003 installed.

msvccompiler.py edited. Key on my machine is
...\MicrosoftSDK\InstalledSDKs\8F9E5EF3-A9A5-491B-A889-C58EFFECE8B3.

vcvars32.bat edited.

>python setup.py build
 running build
 running build_py
 creating build
 creating build\lib.win32-2.4
 copying shapelib.py -> build\lib.win32-2.4
 copying dbflib.py -> build\lib.win32-2.4
 running build_ext
 building 'shapelibc' extension
 creating build\temp.win32-2.4
 creating build\temp.win32-2.4\Release
 ...
 cl.exe seems to be o.k.
 ...
 ... Toolkit 2003\bin\link.exe ... ... shapelibc.pyd ... shapelibc.lib
...
==>
MSVCRT.lib(crtdll.obj) : warning LNK4229:
invalid directive '/manifestdependency:type='win32'
name='Microsoft.VC80.CRT'
version='8.0.50608.0'
processorArchitecture='x86'
publicKeyToken='1fc8b3b9a1e18e3b'' encountered; ignored
<==
...
>python setup.py install
 running install
 running build
 running build_py
 running build_ext
 running install_lib
 copying build\lib.win32-2.4\shapelibc.pyd ->
D:\Python24\Lib\site-packages
 copying build\lib.win32-2.4\shptree.pyd ->
D:\Python24\Lib\site-packages
 copying build\lib.win32-2.4\dbflibc.pyd ->
D:\Python24\Lib\site-packages

Question:
--
Has anyone an idea ?

Thanks,
Andreas

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


Portable apps

2006-12-19 Thread Andreas
Hi Group,

I want to get into writing portable apps that can run solely off a USB
stick, but I have a few problems.

I'm originally a java/.net developer, but I don't want it to be a
requirement that the host computer has .net or a jre installed. I also
am not very fond of developing with VC++ *cry*.

Also done some perl, so I checked out ruby, python, python hey
python seems mature enough and has been around quite long. Yea Python.

So, I wonder if its possible to make distributable python apps that run
off a USB stick?

SQLite seems to be a nice candidate for a USB stick database.

wxPython for the GUI, or maybe even make webapp guis with Django?
Hmm...

Soo

Checked out movable python, seems pretty nice but I wouldn't be able to
distribute my app with movable python since it seems to require a
separate license. :(

Checked out py2exe but the whole django/sqlite business seems a bit
iffy with py2exe.  Probably wouldn't work and the exe could end up
huge.

I'd like to distribute python WITH my app, in a lightweight non-bloated
way, somehow. Don't need a single exe, just a small zip, and one-click
to launch.

Should I be looking at something else than python? TCLKit? StarKIT?

Best regards
Andreas

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


Re: pyFltk-1.1

2006-02-22 Thread andreas
To put it simply, if you think Tkinter is not very easy/simple/fast/...
(fill in your favourite adjective here) then you might want to try
pyFltk. It basically helps you to build simple user interfaces from
Python.

Regards

Andreas Held
http://pyfltk.sourceforge.net

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


Re: Py2Exe security

2005-05-03 Thread andreas
On Tue, May 03, 2005 at 06:01:33AM -0700, Terje Johan Abrahamsen wrote:
> 
> Simon Brunning wrote:
> > On 3 May 2005 05:03:00 -0700, Terje Johan Abrahamsen
> <[EMAIL PROTECTED]> wrote:
> > > We have created some programs in Python that are to be distributed
> > > around. The programs will be made into .exe files by py2exe.
> However,
> > > in the source there are certain webadresses, logins and passwords
> that
> > > the programs use, that we would like to keep away from the end
> users.
> > > They will use them thru the program, but we would like them not to
> be
> > > extracted and used separately for other purposes.
> >
> > If your program can access these details, then a suficiently
> > determined attacker can access them too, regardless of what you do.
> 
> Yes, I assume so. Luckily it is not national secrets we are trying to
> hide. But, how does py2exe compare with for example a program written
> in a compiled language like C++? Is it easier to find the info in a
> py2exe .exe than a c++ compiled c++?
About the same. C++ programs do have their string constants as cleartext
in the binary too.

Personally I'd be more concerned about the network side (use https and
verify the server certificate), and debugging tools that might be able
to intercept your traffic anyway.

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


Re: SSL (HTTPS) with 2.4

2005-05-19 Thread andreas
Hi!

HTTPS over a proxy (CONNECT) hasn't worked for a long time in python
(actually it has never worked).

A quick glance at the 2.4 Changelog doesn't suggest that this has been
fixed.

So basically you've got the following options:
a) redo your own http/https support.
b) look around on the net for some patches to httplib (google is your friend)
   be aware that these are quite old patches.
c) using some external solution, like pycURL.

Andreas


On Thu, May 19, 2005 at 12:53:11PM -0400, Andrew Bushnell wrote:
> Thanks for the update. I will/can keep you posted. I know for a fact we 
> use a Squid proxy which sounds like what you are using. I am going to 
> check out the faq you sent and see what it comes up with. I have also 
> been perusing the net a bit and looking at other client packages and see 
> if they work, such as cURL etc.
> 
> Thanks,
> 
> Andrew
> 
> Bloke wrote:
> > Andrew,
> > 
> > It seems I'm not the only one going nuts here.  I have just spent the
> > last 4 hrs stepping through the code in the debugger.  It seems to get
> > stuck somewhere in the socket module (when it calls ssl) but haven't as
> > yet figured out exactly where.
> > 
> > I am _very_ interested to find that you have the same prob with a
> > non-authenticating proxy.  I had considered I was doing something wrong
> > with the authentication, but from what you say, and from what I have
> > deduced from the code, it is not the authentication that is at fault.
> > 
> > Like you, a standard browser works fine, so I'm inclined to think there
> > is something buggy with the way the sockets module talks to the proxy.
> > There has been some suggestion that it may me a 'Microsoftish' proxy
> > which is at fault, but I believe it is a Squid proxy our company uses.
> > 
> > There is an interesting note here (
> > http://www.squid-cache.org/Doc/FAQ/FAQ-11.html  setcion 11.34 )
> > regarding malformed https requests sent through Squid with buggy
> > clients.  It may be worth looking into.
> > 
> > Anyway, if you have any luck, _please_ let me know - I'm getting
> > desparate.
> > 
> 
> -- 
> 
> Andrew Bushnell
> Lead Development Engineer
> Fluent Inc.
> 10 Cavendish Court
> Centerra Resource Park
> Lebanon, NH  03766
> [EMAIL PROTECTED]
> Phone: 603-643-2600, ext. 757
> Fax: 603-643-1721
> www.fluent.com
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Cannot allocate memory when using os.spawn for moving files

2009-03-17 Thread Andreas

Hello there,

I have a problem moving files from my local harddrive to a NFS share 
using a Python script.
The script is used to run a model which produces large (~500MB) binary 
output files. The model itself is a Fortran program, and I call it from 
my script using the line


os.spawnlp(os.P_WAIT, 'time', 'time', OPT.binary)

where OPT.binary is the filename to be run. This works flawlessly.

However, in order not to clutter up my harddrive, I want to move the 
generated files to a network location after each model run. To save 
time, I use os.P_NOWAIT here:


os.spawnlp(os.P_NOWAIT, 'mv', 'mv', LOCALFILENAME, REMOTEFILENAME)

where LOCALFILENAME is some string like '/home/andreas/model.bin' and 
REMOTEFILENAME is some string like '/home/nfs/model-output/'.


Here I have the problem that after about every 10th model run, I get an 
error saying


Traceback (most recent call last):
  File "../../../../pyiup/b3dctm/run_b3dctm.py", line 281, in 
main()
  File "../../../../pyiup/b3dctm/run_b3dctm.py", line 71, in main
copy_model_output()
  File "../../../../pyiup/b3dctm/run_b3dctm.py", line 162, in 
copy_model_output
os.spawnlp(os.P_NOWAIT, 'mv', 'mv', get_base_filename(RUNDATE) + 
'.pdg', 
os.path.join(OPT.datastoragepath,OPT.modelname,OPT.runname,RUNDATE.strftime('%Y/

%m')))
  File "/usr/lib64/python2.5/os.py", line 635, in spawnlp
return spawnvp(mode, file, args)
  File "/usr/lib64/python2.5/os.py", line 584, in spawnvp
return _spawnvef(mode, file, args, None, execvp)
  File "/usr/lib64/python2.5/os.py", line 530, in _spawnvef
pid = fork()
OSError: [Errno 12] Cannot allocate memory

And my Python script dies.

Is there anyone who can help me with this problem? I'm on Ubuntu 8.04 
64bit with Python 2.5. I am willing to accept that the moving of the 
files does not always work, but then it would be really helpful if I 
could somehow prevent my script from dying and just try the moving again.


Any help is greatly appreciated!

Cheers,

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


Regex similar to "^(?u)\w$", but without digits?

2009-04-11 Thread Andreas
Hello,

I'd like to create a regex that captures any unicode character, but
not the underscore and the digits 0-9. "^(?u)\w$" captures them also.
Is there a possibility to restrict an expression like "\w" to "\w
without [0-9_]"?
I'm using python 2.5.4

Thanks in advance,
Andreas
--
http://mail.python.org/mailman/listinfo/python-list


Re: global variable not working inside function. Increment

2013-05-13 Thread Andreas Perstinger
"feather.duster.kung.fu"  wrote:
>I'm just learning Python and NONE of the tutorials I read said
>anything about that . In fact they all say a global can be called from
>inside a Function. If possible please contact the ppl that write these
>things.

Well, we don't know which tutorials you read.
So why don't you tell them yourself?

Bye, Andreas
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Illegal seek error with seek() and os.lseek()

2013-05-14 Thread Andreas Perstinger

On 14.05.2013 21:00, krishna2pra...@gmail.com wrote:

  # first, open the file as a plain binary
  try:
  self.file = open(/dev/relpcfpga, "r+b", buffering=0)


Aren't you missing the quotes for "/dev/relpcfpga"?


The method seek() complains "OSError: [Errno 29] Illegal seek"
The device relpcfpga is a char device.


Are you sure that your device is seekable?
Try

f = open("/dev/relpcfpga", "r+b", buffering=0)
print(f.seekable())

Bye, Andreas
--
http://mail.python.org/mailman/listinfo/python-list


Re: PEP 378: Format Specifier for Thousands Separator

2013-05-24 Thread Andreas Perstinger

On 24.05.2013 17:25, Carlos Nepomuceno wrote:



Date: Thu, 23 May 2013 19:29:14 -0700
Subject: Re: PEP 378: Format Specifier for Thousands Separator
From: dihedral88...@gmail.com
[some typical dihedral stuff]


I'm sorry but I don't understand your question.


Don't worry. I guess most people on this list don't understand it either.

It looks like dihedral is a bot although nobody knows for sure. Search 
for some other posts from him/her/it in the archive and form your own 
opinion.


IMHO you can simply ignore him/her/it.

Bye, Andreas

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


Re: netcdF4 variables

2013-06-01 Thread Andreas Perstinger

On 01.06.2013 05:30, Sudheer Joseph wrote:

some hing like a list
xx=nc,variables[:]
should get me all variable names with out other surrounding stuff??

In [4]: ncf.variables
Out[4]: OrderedDict([(u'LON', ),

[SNIP]

It looks like "variables" is an OrderedDict. Thus

>>> ncf.variables.keys()

should return a view (or list, depending on your python version) of all 
keys, i.e. all variable names.


Bye, Andreas
--
http://mail.python.org/mailman/listinfo/python-list


Re: Source code as text/plain

2013-06-04 Thread Andreas Perstinger

On 04.06.2013 00:34, Carlos Nepomuceno wrote:



Date: Mon, 3 Jun 2013 09:06:46 +1000
From: c...@zip.com.au
To: c...@rebertia.com

[...]

http://hg.python.org/cpython/raw-file/tip/Lib/string.py


What's the 'tip' tag?   


http://hg.python.org/cpython/help/tip

Bye, Andreas
--
http://mail.python.org/mailman/listinfo/python-list


Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-09 Thread Andreas Perstinger

On 09.06.2013 11:38, Νικόλαος Κούρας wrote:

s = 'α'
s = s.encode('iso-8859-7').decode('utf-8')
print( s )

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe1 in position 0: 
unexpected end of data

Why this error? because 'a' ordinal value > 127 ?


>>> s = 'α'
>>> s.encode('iso-8859-7')
b'\xe1'
>>> bin(0xe1)
'0b1111'

Now look at the table on https://en.wikipedia.org/wiki/UTF-8#Description 
to find out how many bytes a UTF-8 decoder expects when it reads that value.


Bye, Andreas
--
http://mail.python.org/mailman/listinfo/python-list


Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-10 Thread Andreas Perstinger

On 10.06.2013 09:10, nagia.rets...@gmail.com wrote:

Τη Κυριακή, 9 Ιουνίου 2013 3:31:44 μ.μ. UTC+3, ο χρήστης Steven D'Aprano έγραψε:


py> c = 'α'
py> ord(c)
945


The number 945 is the characters 'α' ordinal value in the unicode charset 
correct?


Yes, the unicode character set is just a big list of characters. The 
946th character in that list (starting from 0) happens to be 'α'.



The command in the python interactive session to show me how many bytes
this character will take upon encoding to utf-8 is:


s = 'α'
s.encode('utf-8')

b'\xce\xb1'

I see that the encoding of this char takes 2 bytes. But why two exactly?


That's how the encoding is designed. Haven't you read the wikipedia 
article which was already mentioned several times?



How do i calculate how many bits are needed to store this char into bytes?


You need to understand how UTF-8 works. Read the wikipedia article.


Trying to to the same here but it gave me no bytes back.


s = 'a'
s.encode('utf-8')

b'a'


The encode method returns a byte object. It's length will tell you how 
many bytes there are:


>>> len(b'a')
1
>>> len(b'\xce\xb1')
2

The python interpreter will represent all values below 256 as ASCII 
characters if they are printable:


>>> ord(b'a')
97
>>> hex(97)
'0x61'
>>> b'\x61' == b'a'
True

The Python designers have decided to use b'a' instead of b'\x61'.


py> c.encode('utf-8')
b'\xce\xb1'


2 bytes here. why 2?


Same as your first question.


py> c.encode('utf-16be')
b'\x03\xb1'


2 byets here also. but why 3 different bytes? the ordinal value of
char 'a' is the same in unicode. the encodign system just takes the
ordinal value end encode, but sinc eit uses 2 bytes should these 2 bytes
be the same?


'utf-16be' is a different encoding scheme, thus it uses other rules to 
determine how each character is translated into a byte sequence.



py> c.encode('iso-8859-7')
b'\xe1'


And also does '\x' means that the value is being respresented in hex way?
and when i bin(6) i see '0b101'

I should expect to see 8 bits of 1s and 0's. what the 'b' is tryign to say?

'\x' is an escape sequence and means that the following two characters 
should be interpreted as a number in hexadecimal notation (see also the 
table of allowed escape sequences: 
http://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals 
).


'0b' tells you that the number is printed in binary notation.
Leading zeros are usually discarded when a number is printed:
>>> bin(70)
'0b1000110'
>>> 0b100110 == 0b00100110
True
>>> 0b100110 == 0b00100110
True

It's the same with decimal notation. You wouldn't say 00123 is different 
from 123, would you?


Bye, Andreas
--
http://mail.python.org/mailman/listinfo/python-list


Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-10 Thread Andreas Perstinger

On 10.06.2013 11:59, Νικόλαος Κούρας wrote:

>>>> s = 'α'
>>>> s.encode('utf-8')
> b'\xce\xb1'


'b' stands for binary right?


No, here it stands for bytes:
http://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals


  b'\xce\xb1' = we are looking at a byte in a hexadecimal format?


No, b'\xce\xb1' represents a byte object containing 2 bytes.
Yes, each byte is represented in hexadecimal format.


if yes how could we see it in binary and decimal represenation?


>>> s = b'\xce\xb1'
>>> s[0]
206
>>> bin(s[0])
'0b11001110'
>>> s[1]
177
>>> bin(s[1])
'0b10110001'

A byte object is a sequence of bytes (= integer values) and support 
indexing.

http://docs.python.org/3/library/stdtypes.html#bytes


Since 2^8 = 256, utf-8 should store the first 256 chars of unicode
charset using 1 byte.

Also Since 2^16 = 65535, utf-8 should store the first 65535 chars of
unicode charset using 2 bytes and so on.

But i know that this is not the case. But i dont understand why.


Because your method doesn't work.
If you use all possible 256 bit-combinations to represent a valid 
character, how do you decide where to stop in a sequence of bytes?



>>>> s = 'a'
>>>> s.encode('utf-8')
> b'a'
utf-8 takes ASCII as it is, as 1 byte. They are the same


EBCDIC and ASCII and Unicode are charactet sets, correct?

iso-8859-1, iso-8859-7, utf-8, utf-16, utf-32 and so on are encoding methods, 
right?



Look at http://www.unicode.org/glossary/ for an explanation of all the 
terms.


Bye, Andreas
--
http://mail.python.org/mailman/listinfo/python-list


OT: e-mail reply to old/archived message (was Re: Encoding questions (continuation))

2013-06-11 Thread Andreas Perstinger

On 10.06.2013 15:56, Νικόλαος Κούρας wrote:

Τη Δευτέρα, 10 Ιουνίου 2013 2:41:07 μ.μ. UTC+3, ο χρήστης Steven
D'Aprano έγραψε:

On Mon, 10 Jun 2013 14:13:00 +0300, Νικόλαος Κούρας wrote:

ps. i tried to post a reply to the thread i opend via thunderbird
mail client, but not as a reply to somne other reply but as  new
mail send to python list. because of that a new thread will be
opened. How can i tell thunderbird to reply to the original
thread and not start a new one?

By replying to an email in that thread.


Yes thats obvious. What is not obvious is how you reply back to a
thread by giving extra info when you are not replying to a mail formt
tha thread or when you ahve deleted the reply for a member

sending the mail to python-list@python.org will just open anew
subject intead of replyign to an opened thread.


You would need to find out the Message-Id of the post you want to reply 
to and then add manually the In-Reply-To and References headers to your 
e-mail using that Id.


It's probably easier to just use the web interface at Gmane.

Bye, Andreas
--
http://mail.python.org/mailman/listinfo/python-list


Re: Receing a form variable as a list instead of as a string

2013-06-11 Thread Andreas Perstinger

On 11.06.2013 12:38, Νικόλαος Κούρας wrote:

but page is a form variable coming from a previous sumbitted form
why the error says 'page' is a list?


RTFM:
"If the submitted form data contains more than one field with the same 
name, the object retrieved by form[key] is not a FieldStorage or 
MiniFieldStorage instance but a list of such instances. Similarly, in 
this situation, form.getvalue(key) would return a list of strings."

http://docs.python.org/3.3/library/cgi.html#using-the-cgi-module

Bye, Andreas
--
http://mail.python.org/mailman/listinfo/python-list


Re: OT: e-mail reply to old/archived message

2013-06-11 Thread Andreas Perstinger

On 11.06.2013 22:14, Νικόλαος Κούρας wrote:

Τη Τρίτη, 11 Ιουνίου 2013 2:21:50 μ.μ. UTC+3, ο χρήστης Andreas Perstinger 
έγραψε:

> sending the mail to python-list@python.org will just open anew
> subject intead of replyign to an opened thread.



You would need to find out the Message-Id of the post you want to reply
to and then add manually the In-Reply-To and References headers to your
e-mail using that Id.


You mean by viewing for example your post as 'view original source', finding
In-Reply-To: <71d585e6-bb98-47b7-9a45-7cde1ba0c...@googlegroups.com>


No, the In-Reply-To header in *my* post is the post *I* have replied to, 
i.e. that's the Message-ID of *your* earlier post.




and then compose a new mail as:

to: Andreas Perstinger 
cc: In-Reply-To: <71d585e6-bb98-47b7-9a45-7cde1ba0c...@googlegroups.com>

is this the way Andrea?


No, the headers would be:
To: python-list@python.org
In-Reply-To: <51b7084e.9040...@gmail.com>
References:  
<51b5bb53$0$29997$c3e8da3$54964...@news.astraweb.com> 
<71d585e6-bb98-47b7-9a45-7cde1ba0c...@googlegroups.com> 
<51b7084e.9040...@gmail.com>


Basically, you should follow RFC 2822 and RFC 1036 if you don't mess up 
with message threading.


You also need to know that you can't add these headers manually in 
Thunderbird out of the box. You would need to edit the configuration.


Bye, Andreas
--
http://mail.python.org/mailman/listinfo/python-list


Re: A certainl part of an if() structure never gets executed.

2013-06-12 Thread Andreas Perstinger

[Please trim your replies to the relevant parts.]

On 12.06.2013 10:54, Νικόλαος Κούρας wrote:

But when it comes to select '==' from month instead of
'==' to be submitted a zero gets submitted and i think the
problem is the way i'm filling up months into the drop down menu which is:


for i, month in enumerate(months):
  print(' %s ' % (i, month) )


the if case does not execute because of the way it checks for None entry
which is: elif '=' not in year:

but if enumerate yields 0 instead of '==' then elif '=' not in
year of course fails.


How often do we need to tell you that you should reread your posts 
before sending them?
You start with telling us you have problems with "month" and then show 
us code regarding "year"



So, i must tell:

for i, month in enumerate(months):
  print(' %s ' % (i, month) )

to somehow return '==' instead of 0 but don't know how.


As with most of your problems you are barking up the wrong tree.
Why not use the actual value you get from the form to check whether you 
have a valid month?

Do you understand why "0" is submitted instead of "=="?

Bye, Andreas
--
http://mail.python.org/mailman/listinfo/python-list


Re: Problem creating a regular expression to parse open-iscsi, iscsiadm output (help?)

2013-06-13 Thread Andreas Perstinger

On 13.06.2013 02:59, rice.cr...@gmail.com wrote:

I am parsing the output of an open-iscsi command that contains
severalblocks of data for each data set. Each block has the format:

[SNIP]

I tried using \s* to swallow the whitespace between the to iSCSI
lines. No joy... However [\s\S]*? allows the regex to succeed. But that
seems to me to be overkill (I am not trying to skip lines of text here.)
Also note that I am using \ + to catch spaces between the words. On the
two problem lines, using \s+ between the label words fails.


Changing

 # Connection state
 iSCSI\ +Connection\ +State:\s+(?P\w+\s*\w*)
 [\s\S]*?<<<<<< without this the regex fails
 # Session state
 iSCSI\ +Session\ +State:\s+(?P\w+)


to
# Connection state
iSCSI\s+Connection\s+State:\s+(?P\w+\s*\w*)\s*
# Session state
iSCSI\s+Session\s+State:\s+(?P\w+)

gives me

>>> # 'test' is the example string
>>> myDetails = [ m.groupdict() for m in regex.finditer(test)]
>>> print myDetails
[{'initiatorIP': '221.128.52.214', 'connState': 'LOGGED IN', 'SID': 
'154', 'ipaddr': '221.128.52.224', 'initiatorName': 
'iqn.1996-04.de.suse:01:7c9741b545b5', 'sessionState': 'LOGGED_IN', 
'iqn': 'iqn.1992-04.com.emc:vplex-8460319f-00000007', 
'tag': '7', 'port': '3260'}]


for your example (same for the original regex).
It looks like it works (Python 2.7.3) and there is something else 
breaking the regex.


Bye, Andreas
--
http://mail.python.org/mailman/listinfo/python-list


Re: Wrong website loaded when other requested

2013-06-13 Thread Andreas Perstinger

On 13.06.2013 16:23, Νικόλαος Κούρας wrote:

Please suggest something of why this happnes.


That's not a Python problem.

BTW both scripts at
http://superhost.gr/~dauwin/metrites.py
and at
http://superhost.gr/~dauwin/cgi-bin/metrites.py
show the world the passwords to your databases in plain text.

Bye, Andreas
--
http://mail.python.org/mailman/listinfo/python-list


Re: Wrong website loaded when other requested

2013-06-13 Thread Andreas Perstinger

On 13.06.2013 20:10, Nick the Gr33k wrote:
[nothing new]

Could you please stop spamming the whole internet with your problems.
Not only that you've posted two similar offtopic messages within only 6 
minutes to this list, you've also crossposted to alt.os.linux (where it 
is offtopic too) and to the forum at devshed.com (at least you've found 
the right subforum there).


Thank you very much!

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


Re: Having a hard time to 'get' bing api search results

2013-06-13 Thread Andreas Perstinger

On 14.06.2013 03:00, Yves S. Garret wrote:

Thanks again Kevin.  I'm deviating from the original thread,
but I've got another issue.  When I try to load the json file
and then parse it, this is the error that I get:
http://bin.cakephp.org/view/1329549559


1) Please don't top post. Put your answer after the parts you are 
replying to.


2) Is Kevin sending his e-mails only to you? I don't get them and they 
aren't in the mailing list archive either.


3) Please copy the traceback you get into your message. Otherwise you 
will reduce the amount of people who are willing to help you because not 
everyone likes to go to an external website just to read them.

So here's it:

>>> import json
>>> import pprint
>>> json_data = open('temp.json')
>>> data = json.load(json_data)
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/local/lib/python2.7/json/__init__.py", line 290, in load
**kw)
  File "/usr/local/lib/python2.7/json/__init__.py", line 338, in loads
return _default_decoder.decode(s)
  File "/usr/local/lib/python2.7/json/decoder.py", line 365, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/lib/python2.7/json/decoder.py", line 381, in raw_decode
obj, end = self.scan_once(s, idx)
ValueError: Expecting property name: line 2 column 1 (char 2)

4) The error message tells you that json.load() can't parse your file 
due to an error at the beginning of line 2. So can you please post the 
first lines of your file?


Bye, Andreas
--
http://mail.python.org/mailman/listinfo/python-list


Re: Having a hard time to 'get' bing api search results

2013-06-14 Thread Andreas Perstinger

On 14.06.2013 20:19, Yves S. Garret wrote:

This is the error that I'm getting right now.

import json
from pprint import pprint
path = '/home/azureuser/temp.json'
with open(path) as data_file:

...   data = json.load(data_file)
...
Traceback (most recent call last):
   File "", line 2, in 
   File "/usr/local/lib/python2.7/json/__init__.py", line 290, in load
 **kw)
   File "/usr/local/lib/python2.7/json/__init__.py", line 338, in loads
 return _default_decoder.decode(s)
   File "/usr/local/lib/python2.7/json/decoder.py", line 365, in decode
 obj, end = self.raw_decode(s, idx=_w(s, 0).end())
   File "/usr/local/lib/python2.7/json/decoder.py", line 381, in raw_decode
 obj, end = self.scan_once(s, idx)
ValueError: Expecting property name: line 2 column 1 (char 2)

Thanks for your inputs Andreas.

Also, this is my JSON file, I'll post again.  Since it's going to be
messy, I'll include a link as well (users can decide what they prefer
to read).
http://bin.cakephp.org/view/1050217914


Ok, I've just copied the text from the site into a file and there is no 
problem loading the file.


You could try the same.

Bye, Andreas
--
http://mail.python.org/mailman/listinfo/python-list


Re: Pattern Search Regular Expression

2013-06-15 Thread Andreas Perstinger
subhabangal...@gmail.com wrote:
>I know this solution but I want to have Regular Expression option.
>Just learning.

http://mattgemmell.com/2008/12/08/what-have-you-tried/

Just spell out what you want:
A word at the beginning, followed by any text, followed by a word at
the end.
Now look up the basic regex metacharacters and try to come up with a
solution (Hint: you will need groups)

http://docs.python.org/3/howto/regex.html#regex-howto
http://docs.python.org/3/library/re.html#regular-expression-syntax

Bye, Andreas
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Don't feed the troll...

2013-06-15 Thread Andreas Perstinger
Nick the Gr33k  wrote:
>You are spamming my thread.

Well, you don't own this thread. In fact nobody owns it. This is a
public forum and thus anybody can answer to any post as he likes.

Bye, Andreas
-- 
http://mail.python.org/mailman/listinfo/python-list


OT: C vs Python terminology (was: A certainl part of an if() structure never gets executed)

2013-06-16 Thread Andreas Perstinger

On 16.06.2013 08:32, Denis McMahon wrote:

C:

int a, b;
b = 6;
a = b;

In C, this places the numeric value 6 into the memory location identified
by the variable "b",


so far so good.


then copies the value from the location pointed to by "b" into the
location pointed to by "a".


Wrong. Neither "a" nor "b" are pointers, thus they don't point to a 
memory location.

This part should be written as
"then copies the value at the location identified by "b" to the location 
identified by "a".



b is a pointer to a memory location containing the value 6

> a is a pointer to another memory location also containing the value 6

Again, neither "a" nor "b" are pointers.
"b" is the name of a memory location containing the integer value 6.
"a" is the name of another memory location containing the integer value 6.


Python:

b = 6
a = b

In Python, this first puts the value 6 in in a memory location and points
"b" at that memory location, then makes "a" point to the same memory
location as "b" points to.

b is a pointer to a memory location containing the value 6
a is a pointer to the same memory location


I wouldn't use the term "pointer" in context with Python. Using the 
terms from the language reference I would write that as
"In Python, this first creates an integer object with value 6 and then 
binds the name "b" to it. Then it binds the name "a" to the same object.
Thus both "a" and "b" reference the same object, i.e. they are different 
names for the same object."


Bye, Andreas
--
http://mail.python.org/mailman/listinfo/python-list


Re: OT: C vs Python terminology

2013-06-16 Thread Andreas Perstinger

On 16.06.2013 14:55, Dave Angel wrote:

On 06/16/2013 07:22 AM, Andreas Perstinger wrote:

On 16.06.2013 08:32, Denis McMahon wrote:

C:

^



int a, b;
b = 6;
a = b;

In C, this places the numeric value 6 into the memory location identified

^


by the variable "b",


so far so good.


then copies the value from the location pointed to by "b" into the
location pointed to by "a".


Wrong. Neither "a" nor "b" are pointers, thus they don't point to a
memory location.
This part should be written as
"then copies the value at the location identified by "b" to the location
identified by "a".


But it doesn't.  It binds b to the same object to which a is currently
bound.


Are you aware that Denis was talking about the behaviour of C in the 
above quote?



b is a pointer to a memory location containing the value 6

 > a is a pointer to another memory location also containing the value 6

Again, neither "a" nor "b" are pointers.
"b" is the name of a memory location containing the integer value 6.
"a" is the name of another memory location containing the integer value 6.



Not even close.  If you don't like the terms "bound" or "points", the
perhaps you'd be happy with "b" is the name that currently knows how to
find an int object containing 6.  That object has no name, and never
will.  And it can exist for a long time with no names directly bound to it.


Again, Denis was talking about C.

Bye, Andreas
--
http://mail.python.org/mailman/listinfo/python-list


Re: Help me with the script? How to find items in csv file A and not in file B and vice versa

2013-06-18 Thread Andreas Perstinger
alonn...@gmail.com wrote:
>and when I run it I get an invalid syntex error and (as a true newbie
>I used a GUI)in_a_not_b is highlighted in the with open("inAnotB.csv",
>"wb") as f: 
>writer = csv.writer(f) 
>writer.writerows([item] for item in_a_not_b)
 

The syntax for the for-clause in a comprehension is

for x in something

thus you are missing the "in" keyword:

writer.writerows([item] for item in in_a_not_b)

Bye, Andreas
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A few questiosn about encoding

2013-06-20 Thread Andreas Perstinger
Rick Johnson  wrote:
>
> Since we're on the subject of Unicode:
>
>One the most humorous aspects of Unicode is that it has
>encodings for Braille characters. Hmm, this presents a
>conundrum of sorts. RIDDLE ME THIS?!
>
>Since Braille is a type of "reading" for the blind by
>utilizing the sense of touch (therefore DEMANDING 3
>dimensions) and glyphs derived from Unicode are
>restrictively two dimensional, because let's face it people,
>Unicode exists in your computer, and computer screens are
>two dimensional... but you already knew that -- i think?,
>then what is the purpose of a Unicode Braille character set?
>
>That should haunt your nightmares for some time.

>From http://www.unicode.org/versions/Unicode6.2.0/ch15.pdf
"The intent of encoding the 256 Braille patterns in the Unicode
Standard is to allow input and output devices to be implemented that
can interchange Braille data without having to go through a
context-dependent conversion from semantic values to patterns, or vice
versa. In this manner, final-form documents can be exchanged and
faithfully rendered."

http://files.pef-format.org/specifications/pef-2008-1/pef-specification.html#Unicode

I wish you a pleasant sleep tonight.

Bye, Andreas
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question about mailing list rules

2013-07-12 Thread Andreas Perstinger

On 12.07.2013 01:59, Devyn Collier Johnson wrote:

Am I allowed to ask questions like "Here is my code. How can I optimize
it?" on this mailing list?


If it's written in Python, why not?

But that doesn't mean you are guaranteed to get an answer :-).

And please read http://sscce.org/ before posting your latest 10,000 line 
program :-)


Bye, Andreas

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


Re: ANN: PollyReports 1.5 -- Band-oriented PDF Report Generator

2012-07-11 Thread Andreas Perstinger
On Thu, 12 Jul 2012 10:41:52 +1000 
Simon Cropper  wrote:

> That said... with more than a passing interest in software and
> content licensing I looked at how the work was licensed. A
> none-standard license like this makes most people stop and think
> "will this be a problem if I use this in my work?" How compatible is
> your license with the main software licenses currently available?

Do you mean this license?:
http://packages.python.org/PollyReports/license.html

It's the standard license for NetBSD projects and approved by OSI:
http://www.opensource.org/licenses/bsd-license.php

and GPL-compatible:
http://www.gnu.org/licenses/license-list.html#FreeBSD

Bye, Andreas
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: PollyReports 1.5 -- Band-oriented PDF Report Generator

2012-07-12 Thread Andreas Perstinger
On Thu, 12 Jul 2012 16:59:06 +1000 
Chris Angelico  wrote:

> On Thu, Jul 12, 2012 at 3:35 PM, Andreas Perstinger
>  wrote:
> > Do you mean this license?:
> > http://packages.python.org/PollyReports/license.html
> >
> > It's the standard license for NetBSD projects and approved by OSI:
> > http://www.opensource.org/licenses/bsd-license.php
> >
> > and GPL-compatible:
> > http://www.gnu.org/licenses/license-list.html#FreeBSD
> 
> Can you state that on the page, perhaps? It'd mean that anyone who's
> familiar with the license can read one keyword and know what the terms
> are, rather than dig through the full text to see if it's really the
> same or not.

I'm not responsible for any of the tree pages I've mentioned.

I've just looked at the "PollyReports"-license page because I was
curious which "strange" license the original author uses. Then I noticed
it's just one of the BSD-licenses, used Wikipedia to confirm it and
searched for the two other pages to show that it isn't problematic at
all.

Bye, Andreas
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Beautiful Soup Table Parsing

2012-08-09 Thread Andreas Perstinger

On 09.08.2012 01:58, Tom Russell wrote:

For instance this code below:

soup = 
BeautifulSoup(urlopen('http://online.wsj.com/mdc/public/page/2_3021-tradingdiary2.html?mod=mdc_pastcalendar'))

table = soup.find("table",{"class": "mdcTable"})
for row in table.findAll("tr"):
 for cell in row.findAll("td"):
 print cell.findAll(text=True)

brings in a list that looks like this:


[snip]


What I want to do is only be getting the data for NYSE and nothing
else so I do not know if that's possible or not. Also I want to do
something like:

If cell.contents[0] == "Advances":
 Advances = next cell or whatever??---> this part I am not sure how to do.

Can someone help point me in the right direction to get the first data
point for the Advances row? I have others I will get as well but
figure once I understand how to do this I can do the rest.


To get the header row you could do something like:

header_row = table.find(lambda tag: tag.td.string == "NYSE")

From there you can look for the next row you are interested in:

advances_row = header_row.findNextSibling(lambda tag: tag.td.string == 
"Advances")


You could also iterate through all next siblings of the header_row:

for row in header_row.findNextSiblings("tr"):
 # do something

Bye, Andreas
--
http://mail.python.org/mailman/listinfo/python-list


RE: something about split()???

2012-08-14 Thread Andreas Tawn
> I have a question about the split function? surpose a = "|",and when I use 
> a.split("|") , I got the list
> ['"",""] ,but I want to get the empty list,what should I do ?

Something like...

>>> [x for x in "|".split("|") if x]
[]

Cheers,

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


Re: help me debug my "word capitalizer" script

2012-08-22 Thread Andreas Perstinger

On 22.08.2012 08:21, Santosh Kumar wrote:

with open(givenfile) as file:
 # List to store the capitalised lines.
 lines = []
 for line in file:
 # Split words by spaces.
 words = line.split(' ')


The last element in your "words" list will still have a newline 
character appended to it.

You could probably use line.split().
See also the docs:
http://docs.python.org/py3k/library/stdtypes.html#str.split


 for i, word in enumerate(words):
 if len(word.strip(punctuation)) > 3:
 # Capitalise and replace words longer than 3 (without
punctuation)
 words[i] = word.capitalize()
 # Join the capitalised words with spaces.
 lines.append(' '.join(words))


This rebuilds the line including a newline character at the end.


 # Join the capitalised lines by the line separator
 capitalised = linesep.join(lines)


Because you haven't removed the newline character from each line, 
joining them with "linesep" introduces a second newline character after 
each line.


Bye, Andreas
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python list archives double-gzipped?

2012-08-27 Thread Andreas Perstinger

On 27.08.2012 03:40, Tim Chase wrote:

So it looks like some python-list@ archiving process is double
gzip'ing the archives.  Can anybody else confirm this and get the
info the right people?


In January, "random joe" noticed the same problem[1].
I think, Anssi Saari[2] was right in saying that there is something 
wrong in the browser or server setup, because I notice the same 
behaviour with Firefox, Chromium, wget and curl.


$ ll *July*
-rw-rw-r-- 1 andreas andreas 747850 Aug 27 13:48 chromium_2012-July.txt.gz
-rw-rw-r-- 1 andreas andreas 748041 Aug 27 13:41 curl_2012-July.txt.gz
-rw-rw-r-- 1 andreas andreas 747850 Aug 27 13:48 firefox_2012-July.txt.gz
-rw-rw-r-- 1 andreas andreas 748041 Aug  2 03:27 wget_2012-July.txt.gz

The browsers get a double gzipped file (size 747850) whereas the 
download utilities get a normal gzipped file (size 748041).


After looking at the HTTP request and response headers I've noticed that 
the browsers accept compressed data ("Accept-Encoding: gzip, deflate") 
whereas wget/curl by default don't. After adding that header to 
wget/curl they get the same double gzipped file as the browsers do:


$ ll *July*
-rw-rw-r-- 1 andreas andreas 747850 Aug 27 13:48 chromium_2012-July.txt.gz
-rw-rw-r-- 1 andreas andreas 748041 Aug 27 13:41 curl_2012-July.txt.gz
-rw-rw-r-- 1 andreas andreas 747850 Aug 27 13:40 
curl_encoding_2012-July.txt.gz

-rw-rw-r-- 1 andreas andreas 747850 Aug 27 13:48 firefox_2012-July.txt.gz
-rw-rw-r-- 1 andreas andreas 748041 Aug  2 03:27 wget_2012-July.txt.gz
-rw-rw-r-- 1 andreas andreas 747850 Aug  2 03:27 
wget_encoding_2012-July.txt.gz


I think the following is happening:
If you send the "Accept-Encoding: gzip, deflate"-header, the server will 
gzip the file a second time (which is arguably unnecessary) and responds 
with "Content-Encoding: gzip" and "Content-Type: application/x-gzip" 
(which is IMHO correct according to RFC2616/14.11 and 14.17[3]).
But because many servers apparently don't set correct headers, the 
default behaviour of most browsers nowadays is to ignore the 
content-encoding for gzip files (application/x-gzip - see bug report for 
firefox[4] and chromium[5]) and don't uncompress the outer layer, 
leading to a double gzipped file in this case.


Bye, Andreas

[1] http://mail.python.org/pipermail/python-list/2012-January/617983.html

[2] http://mail.python.org/pipermail/python-list/2012-January/618211.html

[3] http://www.ietf.org/rfc/rfc2616

[4] https://bugzilla.mozilla.org/show_bug.cgi?id=610679#c5

[5] http://code.google.com/p/chromium/issues/detail?id=47951#c9
--
http://mail.python.org/mailman/listinfo/python-list


Re: Cut out XML subtree

2012-08-29 Thread Andreas Perstinger
On Wed, 29 Aug 2012 18:17:18 +0200 
Florian Lindner  wrote:
> I want to cut out an XML subtree like that:
[snip] 
> Is there a way I can do that using etree or DOM? The first is
> prefered...

Python 3.2.2 (default, Sep  5 2011, 22:09:30) 
[GCC 4.6.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import xml.etree.ElementTree as etree
>>> test = """
... 
... 
... Element A.1
... Element A.2
... 
... 
... Element B.1
... Element B.2
... 
... """
>>> tree = etree.fromstring(test)
>>> subA = tree.find("subA")
>>> tree.remove(subA)
>>> new = etree.tostring(tree, encoding="unicode")
>>> print(new)


Element B.1
Element B.2



Bye, Andreas
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: focus on jtextfield

2012-09-04 Thread Andreas Perstinger

On 04.09.2012 11:34, Paolo wrote:

how do I know if a JTextField has the focus?
thank to all


Look there:
http://www.catb.org/esr/faqs/smart-questions.html#forum

Bye, Andreas
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to tell people to ask questions the smart way

2012-09-05 Thread Andreas Perstinger

On 05.09.2012 01:05, Ben Finney wrote:

Andreas Perstinger  writes:


On 04.09.2012 11:34, Paolo wrote:
> how do I know if a JTextField has the focus?
> thank to all

Look there:
http://www.catb.org/esr/faqs/smart-questions.html#forum


That is an unhelpful response.


So we have to agree to disagree.

EOD.

Bye, Andreas
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python launcher (PEP 397) and emacs python-mode.el

2013-01-31 Thread Andreas Röhler

Am 31.01.2013 10:03, schrieb Thomas Heller:

Has someone managed to patch python-mode.el to use
the PEP 397 python launcher when you hit C-c C-c?

It seems that emacs should parse the shebang line in the edited
python script and pass the corresponding arguments to py.exe.



Yes, that's the way python-mode.el acts by default.

AFAIU that launcher is implemented in Python3.3 and should not need any patch 
at all.
Should it not work, please file a bug-report at

https://bugs.launchpad.net/python-mode

Andreas


Thomas





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


Re: Python launcher (PEP 397) and emacs python-mode.el

2013-01-31 Thread Andreas Röhler

Am 31.01.2013 17:35, schrieb Thomas Heller:

Am 31.01.2013 12:05, schrieb Andreas Röhler:

Am 31.01.2013 10:03, schrieb Thomas Heller:

Has someone managed to patch python-mode.el to use
the PEP 397 python launcher when you hit C-c C-c?

It seems that emacs should parse the shebang line in the edited
python script and pass the corresponding arguments to py.exe.



Yes, that's the way python-mode.el acts by default.

AFAIU that launcher is implemented in Python3.3 and should not need any
patch at all.
Should it not work, please file a bug-report at

https://bugs.launchpad.net/python-mode


Well, let me make these remarks:

1. I'm on Windows, using gnu-emacs 24.2.1, and python-mode.el 6.1.0.
I do not understand how the shebang line is used by python-mode.el,


it uses py-shebang-regexp to determine
- if a shebang is given
- if, yes, which interpreter to run


depending on what I write into it either 'python.exe' is started when
I hit C-c C-c, or I get 'Spawning child process: invalid argument'.
The latter occurs most often when the shebang string contains 'jython'.


please file a bug-report giving some example script which triggers the bug




2. I would like to use the PEP 397 python launcher to start the python
version that is specified in the shebang line.
The python launcher py.exe parses this line when I run 'py script.py',
and then starts the corresponding python interpreter version.
The launcher parses the shebang line by its own rules (see pep397 for
exact details).  One example is this:


#!/usr/bin/python3.1-32
import sys; print(sys.version)


The python launcher starts 'c:\Python31\python.exe -3.1-32 script.py'.



unfortunatly don't have a windows at my disposal.

At linux it would run exactly the interpreter specified. Might be okay for 
windows as shown.



I would like emacs to do the same; however this would require emacs
to do the same shebang line parsing as the launcher does.



So we do - looks like python-mode.el precedes PEP 397  :)

Expecting the bug elsewhere.


Thomas


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


Re: Python launcher (PEP 397) and emacs python-mode.el

2013-01-31 Thread Andreas Röhler

Am 01.02.2013 00:59, schrieb Vinay Sajip:

Thomas Heller  ctypes.org> writes:


What I meant to write is this:

when the shebang line in script.py contains this:
#!/usr/bin/python3.1-32
then emacs SHOULD run
py.exe -3.1-32 script.py
and the launcher runs
c:\Python31\python.exe script.py


IMO it would be better for emacs to just run

py.exe script.py

and py.exe can read the shebang and do the right thing. This saves the emacs 
code
from having to duplicate the shebang line processing logic that py.exe uses
(which, as we know, is unusual. So for a cross-platform you can have a shebang
line of #!/usr/bin/python3.2, and on Windows it will still call the appropriate
Python 3.2 even if it's not in /usr/bin, as there's no /usr/bin :-))

Regards,

Vinay Sajip





https://bugs.launchpad.net/python-mode/+bug/1112207
--
http://mail.python.org/mailman/listinfo/python-list


Dealing with the __str__ method in classes with lots of attributes

2012-05-10 Thread Andreas Tawn
Say I've got a class...

class test(object):
def __init__(self):
self.foo = 1
self.bar = 2
self.baz = 3

I can say...

def __str__(self):
   return "foo: {0}\nbar: {1}\nbaz: {2}".format(self.foo, self.bar, self.baz)

and everything's simple and clean and I can vary the formatting if I need to.

This gets ugly when the class has a lot of attributes because the string 
construction gets very long.

I can do...

return "foo: {0}\nbar: {1}\nbaz: {2}".format(self.foo,
self.bar,
self.baz)

which is an improvement, but there's still a very long line.

And there's also something like...

return "\n".join((": ".join((str(k), str(self.__dict__[k]))) for k in 
self.__dict__))

which is a nice length, but I lose control of the order of the attributes and 
the formatting is fixed. It also looks a bit too much like Lisp ;o)

Is there a better way?

Cheers,

Drea

p.s. I may want to substitute __repr__ for __str__ perhaps?
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Dealing with the __str__ method in classes with lots of attributes

2012-05-10 Thread Andreas Tawn
> On Thu, May 10, 2012 at 11:33 PM, Andreas Tawn 
> wrote:
> > Say I've got a class...
> >
> > class test(object):
> >    def __init__(self):
> >        self.foo = 1
> >        self.bar = 2
> >        self.baz = 3
> >
> > I can say...
> >
> > def __str__(self):
> >   return "foo: {0}\nbar: {1}\nbaz: {2}".format(self.foo, self.bar,
> > self.baz)
> 
> This might be of use:
> 
> return """foo: {foo}
> bar: {bar}
> baz: {baz}""".format(**self.__dict__)
> 
> You're repeating yourself a bit, but this allows the labels to differ from 
> the format
> tags. If you're certain that you don't need that flexibility, you could 
> generate the
> format string dynamically:
> 
> return "\n".join(x+": {"+x+"}" for x in
> ("foo","bar","baz")).format(**self.__dict__)
> 
> That scales more nicely as the number of elements desired increases (while 
> still
> being 100% explicit - the presence and order of elements is governed by the 
> tuple),
> but is a bit inflexible and complicated.
> I'd be inclined toward the triple-quoted-string one.

I considered the triple quote string one, but it's not very PEP 8 compatible in 
a real class because it includes the indentation in the formatted string.

To make it print properly, it has to look like this...

def __str__(self):
return """foo: {foo}
bar: {bar}
baz: {baz}""".format(**self.__dict__)

I didn't realise I could do implicit line continuation inside a list 
comprehension. That might be the best way.

Even more so with continuation lines inside the attribute name tuple.

def __str__(self):
return "\n".join(x+": {"+x+"}" for x in
("foo",
"bar",
"baz")).format(**self.__dict__)

Still feels a bit icky though.
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Dealing with the __str__ method in classes with lots of attributes

2012-05-11 Thread Andreas Tawn
> This issue bit me once too often a few months ago, and now I have a class 
> called
> "O" from which I often subclass instead of from "object".
> Its main purpose is a friendly __str__ method, though it also has a friendly 
> __init__.
> 
> Code:
> 
> class O(object):
>   ''' A bare object subclass to allow storing arbitrary attributes.
>   It also has a nicer default str() action, and an aggressive repr().
>   '''
> 
>   def __init__(self, **kw):
> ''' Initialise this O.
> Fill in attributes from any keyword arguments if supplied.
> This call can be omitted in subclasses if desired.
> '''
> for k in kw:
>   setattr(self, k, kw[k])
> 
>   def __str__(self):
> return ( "<%s %s>"
>  % ( self.__class__.__name__,
>  ",".join([ "%s=%s" % (attr, getattr(self, attr))
> for attr in sorted(dir(self)) if 
> attr[0].isalpha()
>   ])
>)
>)

This is a very interesting solution.

I think it might be better suited (for my purpose) to __repr__ rather than 
__str__, mostly because I still lose control of the order the attributes appear.

I really like the general idea of subclassing object though, because I often 
have classes with dozens of attributes and __init__ gets very messy.

Chris' dynamically generated format string looks to be my best bet in the 
absence of a perfect solution.

Cheers,

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


RE: Dealing with the __str__ method in classes with lots of attributes

2012-05-11 Thread Andreas Tawn
> I have no idea why using __repr__ versus __str__ would make any difference in 
> the
> order of the attributes. They're going to come out in the order you specify,
> regardless of what you name your method.  If you don't like the arbitrary 
> order you
> get from the dictionary, then either sort it, or provide an explicit list.

Only that, as the docs say, __repr__ should represent the entire object that 
could be used to build a new object with the same value. For that task the 
order of the attributes is immaterial.

I want __str__ to give me something easily readable and ordered in a way that's 
conveys some meaning about the attributes. It's also helpful to not have to 
display every attribute, of which there may be dozens.
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Dealing with the __str__ method in classes with lots of attributes

2012-05-11 Thread Andreas Tawn
> > It's also helpful to not have to display every attribute, of which there 
> > may be
> dozens.
> 
> Do I detect a code smell here?

Possibly. I'll often try to subdivide into several simpler types, but sometimes 
that makes the code more complex than it needs to be.
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Dealing with the __str__ method in classes with lots of attributes

2012-05-11 Thread Andreas Tawn
> >> It's also helpful to not have to display every attribute, of which
> >> there may be dozens.
> >
> > Do I detect a code smell here?
> >
> I think so, Murphy's law dictates that the attribute you're interested in 
> will not be
> displayed anyway.

That's what __repr__'s for.
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Dealing with the __str__ method in classes with lots of attributes

2012-05-14 Thread Andreas Tawn
> p.s. Is Python seeing a lot of use at Ubisoft or is this just for personal 
> interest (or
> perhaps both)?

We do use Python a fair bit, mostly for build systems and data mining, but also 
because it's the built-in script language for Motionbuilder.
-- 
http://mail.python.org/mailman/listinfo/python-list


Attribute Error in xml.sax.saxutils.XMLGenerator on Arch Linux (64bit)

2011-06-29 Thread Andreas Hasenkopf
Hi there,
after switching from Ubuntu to Arch Linux I noticed a disturbing problem
in a Python script I wrote (see
http://sourceforge.net/projects/emcdutilityprog/files/).
Using Windows (Python 2.6) and Ubuntu 11.04 (Python 2.7) I did not
experience any problems.
Using Arch Linux (Python 2.7) I got the following errors:

Traceback (most recent call last):
  File "/usr/local/bin/emcd", line 1663, in settings_dialog
self.settings.dialog(self.window)
  File "/usr/local/bin/emcd", line 1502, in dialog
self.save()
  File "/usr/local/bin/emcd", line 1445, in save
self.prepare_writing()
  File "/usr/local/bin/emcd", line 1414, in prepare_writing

self.xmltree.startElementNS((None,u'EELS-GUI-Settings'),u'EELS-GUI-Settings',attrs,True)
  File "/usr/local/bin/emcd", line 1352, in startElementNS
self._write('\t'*self.counter)
AttributeError: Generator instance has no attribute '_write'

I'm using the '_write' method in an instance Generator, which has
xml.sax.saxutils.XMLGenerator as parent. I'm using it to make the
resulting xml file more readable for humans.

Have you encountered a similar problem? Maybe you could suggest me some
possible solutions to my little problem?

Thanks a lot
Andi

-- 
Andreas Hasenkopf
Phone: +49 151 11728439
Homepage: http://www.hasenkopf2000.net
GPG Pub Key: http://goo.gl/4mOsM



signature.asc
Description: OpenPGP digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1")

2011-08-21 Thread Andreas Löscher
> What the precise difference (semantics and speed) is between the 
> BINARY_ADD and INPLACE_ADD opcodes, I dunno. Look in the Python source 
> code or maybe someone knows it from memory :-)
> 
> Irmen
> 
from Python/ceval.c:

1316case BINARY_ADD:
1317w = POP();
1318v = TOP();
1319if (PyInt_CheckExact(v) && PyInt_CheckExact(w)) {
1320/* INLINE: int + int */
1321register long a, b, i;
1322a = PyInt_AS_LONG(v);
1323b = PyInt_AS_LONG(w);
1324/* cast to avoid undefined behaviour
1325   on overflow */
1326i = (long)((unsigned long)a + b);
1327if ((i^a) < 0 && (i^b) < 0)
1328goto slow_add;
1329x = PyInt_FromLong(i);
1330}
1331else if (PyString_CheckExact(v) &&
1332 PyString_CheckExact(w)) {
1333x = string_concatenate(v, w, f, next_instr);
1334/* string_concatenate consumed the ref to v */
1335goto skip_decref_vx;
1336}
1337else {
1338  slow_add:
1339x = PyNumber_Add(v, w);
1340}
1341Py_DECREF(v);
1342  skip_decref_vx:
1343Py_DECREF(w);
1344SET_TOP(x);
1345if (x != NULL) continue;
1346break;

1532case INPLACE_ADD:
1533w = POP();
1534v = TOP();
1535if (PyInt_CheckExact(v) && PyInt_CheckExact(w)) {
1536/* INLINE: int + int */
1537register long a, b, i;
1538a = PyInt_AS_LONG(v);
1539b = PyInt_AS_LONG(w);
1540i = a + b;
1541if ((i^a) < 0 && (i^b) < 0)
1542goto slow_iadd;
1543x = PyInt_FromLong(i);
1544}
1545else if (PyString_CheckExact(v) &&
1546 PyString_CheckExact(w)) {
1547x = string_concatenate(v, w, f, next_instr);
1548/* string_concatenate consumed the ref to v */
1549goto skip_decref_v;
1550}
1551else {
1552  slow_iadd:
1553x = PyNumber_InPlaceAdd(v, w);
1554}
1555Py_DECREF(v);
1556  skip_decref_v:
1557Py_DECREF(w);
1558SET_TOP(x);
1559if (x != NULL) continue;
1560break;

As for using Integers, the first case (line 1319 and 1535) are true and
there is no difference in Code. However, Python uses a huge switch-case
construct to execute it's opcodes and INPLACE_ADD cames after
BINARY_ADD, hence the difference in speed. 

To be clear, this is nothing you should consider when writing fast code.
Complexity wise they both are the same. 



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


Re: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1")

2011-08-21 Thread Andreas Löscher
Am Sonntag, den 21.08.2011, 14:52 -0400 schrieb Roy Smith:
> In article ,
>  Christian Heimes  wrote:
> 
> > Am 21.08.2011 19:27, schrieb Andreas Lscher:
> > > As for using Integers, the first case (line 1319 and 1535) are true and
> > > there is no difference in Code. However, Python uses a huge switch-case
> > > construct to execute it's opcodes and INPLACE_ADD cames after
> > > BINARY_ADD, hence the difference in speed. 
> > 
> > I don't think that's the reason. Modern compiles turn a switch statement
> > into a jump or branch table rather than a linear search like chained
> > elif statements.
> 
> This is true even for very small values of "modern".  I remember the 
> Unix v6 C compiler (circa 1977) was able to do this.

What is the difference in speed between a jump table that is searched
from top to bottom in comparison to an ordinary if-then-elif...? The
difference can only be in the search algorithm regarding the table.
Without optimization (linear search) both are the same. If the compiler
applies some magic the difference can be relevant (linear complexity for
if-then-elif... and O(1) if you would use a dictionary). 

Hence the executed code for integers is the same, there must be a slower
path to the code of BINARY_ADD than to INPLACE_ADD. 

How would such an jump table work to behave the same liek a
switch-case-statement? Beware, that things like

   case PRINT_NEWLINE_TO:
1802w = stream = POP();
1803/* fall through to PRINT_NEWLINE */
1804
1805case PRINT_NEWLINE:

must be supported.


Bye the way:
First line of ceval.c since at least Version 2.4
1   
2   /* Execute compiled code */
3   
4   /* XXX TO DO:
5  XXX speed up searching for keywords by using a dictionary
6  XXX document it!
7  */

:-)

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


Re: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1")

2011-08-21 Thread Andreas Löscher
Am Sonntag, den 21.08.2011, 12:53 -0700 schrieb Laurent:
> > With 64 bit 3.2.2 on my Win 7 Pentium, the difference was 4% and with 
> > floats (0.0 and 1.0), 6%
> 
> For floats it is understandable. But for integers, seriously, 4% is a lot. I 
> would never have thought an interpreter would have differences like this in 
> syntax for something as fundamental as adding 1.

It's not as bad as you think. The addition of two integers is a cheap
task (in terms of computation power). If you have two way's to to it,
every little think (jumps in the code etc. ) will have a larger impact
on the execution time than on an expensive operation.

But every improvement on your algorithm will easily result in a
significant shorter execution time than replaceing a+=1 with a=a+1 will
ever do. :-)

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


Re: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1")

2011-08-21 Thread Andreas Löscher
Am Sonntag, den 21.08.2011, 19:38 -0400 schrieb Terry Reedy:
> On 8/21/2011 7:17 PM, Andreas Löscher wrote:
> > Am Sonntag, den 21.08.2011, 14:52 -0400 schrieb Roy Smith:
> >> In article,
> >>   Christian Heimes  wrote:
> >>
> >>> Am 21.08.2011 19:27, schrieb Andreas Lscher:
> >>>> As for using Integers, the first case (line 1319 and 1535) are true and
> >>>> there is no difference in Code. However, Python uses a huge switch-case
> >>>> construct to execute it's opcodes and INPLACE_ADD cames after
> >>>> BINARY_ADD, hence the difference in speed.
> >>>
> >>> I don't think that's the reason. Modern compiles turn a switch statement
> >>> into a jump or branch table rather than a linear search like chained
> >>> elif statements.
> >>
> >> This is true even for very small values of "modern".  I remember the
> >> Unix v6 C compiler (circa 1977) was able to do this.
> >
> > What is the difference in speed between a jump table that is searched
> > from top to bottom in comparison to an ordinary if-then-elif...? The
> > difference can only be in the search algorithm regarding the table.
> > Without optimization (linear search) both are the same. If the compiler
> > applies some magic the difference can be relevant (linear complexity for
> > if-then-elif... and O(1) if you would use a dictionary).
> 
> A jump or branch table is applicable when the case value values are all 
> small ints, like bytes or less. For C, the table is simply an array of 
> pointers (addressess, with entries for unused byte codes would be a void 
> pointer). Hence, O(1) access.
> https://secure.wikimedia.org/wikipedia/en/wiki/Jump_table
> 
> > Hence the executed code for integers is the same, there must be a slower
> > path to the code of BINARY_ADD than to INPLACE_ADD.
> >
> > How would such an jump table work to behave the same liek a
> > switch-case-statement? Beware, that things like
> >
> > case PRINT_NEWLINE_TO:
> > 1802w = stream = POP();
> > 1803/* fall through to PRINT_NEWLINE */
> 
> add jump to address of the code for PRINT_NEWLINE
> 
> > 1804
> > 1805case PRINT_NEWLINE:
> >
> > must be supported.
> 

:-) too easy or too late 
thanks

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


RE: Remove all directories using wildcard

2011-03-18 Thread Andreas Tawn
> I'm new to python and I am trying to figure out how to remove all sub
> directories from a parent directory using a wildcard.  For example,
> remove all sub directory folders that contain the word "PEMA" from the
> parent directory "C:\Data".
> 
> I've trying to use os.walk with glob, but I'm not sure if this is the
> right path to take.
> 
> Thanks for any suggestions!

I think I'd do something like this (untested).

import os, shutil

startDir = r"C:\Data"

for item in os.listdir(startDir):
folder = os.path.join(startDir, item)
if os.path.isdir(folder) and "PEMA" in item:
shutil.rmtree(folder)

Cheers,

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


RE: Vectors

2011-04-20 Thread Andreas Tawn
> Algis Kabaila  writes:
> 
> > Are there any modules for vector algebra (three dimensional
> > vectors, vector addition, subtraction, multiplication [scalar
> > and vector]. Could you give me a reference to such module?
> 
> NumPy has array (and matrix) types with support for these basic
> operations you mention. See the tutorial at http://numpy.scipy.org/

You might also want to consider http://code.google.com/p/pyeuclid/

Cheers,

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


RE: Vectors

2011-04-20 Thread Andreas Tawn
> On Apr 20, 6:43 am, Andreas Tawn  wrote:
> > > Algis Kabaila  writes:
> >
> > > > Are there any modules for vector algebra (three dimensional
> > > > vectors, vector addition, subtraction, multiplication [scalar
> > > > and vector]. Could you give me a reference to such module?
> >
> > > NumPy has array (and matrix) types with support for these basic
> > > operations you mention. See the tutorial athttp://numpy.scipy.org/
> >
> > You might also want to considerhttp://code.google.com/p/pyeuclid/
> >
> > Cheers,
> >
> > Drea
> 
> Pyeuclid docs don't mention dot or cross products.
> RJB

http://partiallydisassembled.net/euclid/vector-classes.html#SECTION00222

Bottom of the page.

Cheers,

Drea

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


RE: What other languages use the same data model as Python?

2011-05-05 Thread Andreas Tawn
> Steven D'Aprano wrote:
> 
> > Some day, we'll be using quantum computers without memory addresses,
> [ ...
> ] it will still be possible to
> > represent data indirectly via *some* mechanism.
> 
> :)  Cool!  Pass-by-coincidence!  And Python 3 already has dibs on the
> 'nonlocal' keyword!
> 
>   Mel.
> 

If True and False:
waveFunction.collapse(cat)


That's going to be fun ;o)

Cheers,

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


Newbie: Python 3.2, search for module dBase + Excel

2011-05-17 Thread Andreas Mosmann

Hi,

I am new to python and so I decided to use python 3.2
But, if I found out correctly, the are no working modules concerning 
Excel and dBase for this python version.
Did I only misunderstand anything or is this right? I tried to download 
and use pydbf and pyexcelerator but both gave me an syntax error inside 
the modules and I somewhere read, that both modules only exist for 
version 2.X


Is there a way for me to use them anyway or do I have to change to any 
2.X- Version? If last, which should I install?


Thanks in advance
Andreas

remark: My task is to compare 2 directories incl. subdirs containing 
dBase- Files and find out differencers in FileNames and FileStructures.
Up t now I devided it into 3 lists: OnlyInDir1, OnlyInDir2 and 
InBothDirs. Next step is to put it into an Excel- File with 3 
worksheets. If this would be impossible, so I could save this in any 
other way. But I really need a module that handles dBase- files to 
compare Structures of files with equal names.


My Code up to now is something like
import os
dirV1 = "C:\Path1"
dirV2 = "C:\Path2"

anzL1=0
listV1 = []
for root, dirs, files in os.walk(dirV1):
for file in files:
myFile=os.path.join(root[len(dirV1):], file)
listV1.append(myFile)
anzL1=anzL1+1
print(anzL1)
anzL2=0
anzLG=0
listV2 = []
listGem = []
for root, dirs, files in os.walk(dirV2):
for file in files:
myFile=os.path.join(root[len(dirV2):], file)
try:
listV1.index(myFile)
listV1.remove(myFile)
listGem.append(myFile)
anzL1=anzL1-1
anzLG=anzLG+1
except ValueError:
listV2.append(myFile)
anzL2=anzL2+1


print(anzL1)
print(anzLG)
print(anzL2)



--
wenn email, dann AndreasMosmann  web  de
--
http://mail.python.org/mailman/listinfo/python-list


RE: starting a separate thread in maya

2011-05-20 Thread Andreas Tawn
> Hi,
> I'm using python2.5 in maya 2009 x64 (in linux).

For Maya/Python stuff you'll probably have more success at 
http://www.tech-artists.org/

Cheers,

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


RE: Python sets which support multiple same elements

2011-05-20 Thread Andreas Tawn
> For example, I was writing a program to detect whether two strings are
> anagrams of each other. I had to write it like this:
> 
> def isAnagram(w1, w2):
>   w2=list(w2)
>   for c in w1:
> if c not in w2:
>   return False
> else:
>   w2.remove(c)
>   return True
> 
> But if there was a data structure in python which supported duplicate
> elements(lets call it dset), then I could just write:
> 
> def inAnagram(w1,w2):
>   return dset(w1)==dset(w2)
> 
> Example of some dset methods:
> {1,2,3,3} intersection {4,1,2,3,3,3}  == {1,2,3,3}
> {1,2,3,3} union {4,1,2,3,3,3} == {1,2,3,3,3,4}
> {4,1,2,3,3,3} difference {1,2,3,3} == {4,3}
> 
> Do you think that it would be a good idea to add this kind of data
> structure to python? Or did I overlook some other easy way to solve
> this kind of problems?

Just to do the anagram problem you could do...

def isAnagram(w1, w2):
return sorted(w1) == sorted(w2)

To do the set-like operations, I guess that unless there's some itertools 
witchcraft available, you'd have to make your own dset type that inherits from 
list. Then you can define your own intersection/union etc. methods.

Cheers,

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


Parallel(?) programming with python

2022-08-08 Thread Andreas Croci
tI would like to write a program, that reads from the network a fixed 
amount of bytes and appends them to a list. This should happen once a 
second.


Another part of the program should take the list, as it has been filled 
so far, every 6 hours or so, and do some computations on the data (a FFT).


Every so often (say once a week) the list should be saved to a file, 
shorthened in the front by so many items, and filled further with the 
data coming fom the network. After the first saving of the whole list, 
only the new part (the data that have come since the last saving) should 
be appended to the file. A timestamp is in the data, so it's easy to say 
what is new and what was already there.


I'm not sure how to do this properly: can I write a part of a program 
that keeps doing its job (appending data to the list once every second) 
while another part computes something on the data of the same list, 
ignoring the new data being written?


Basically the question boils down to wether it is possible to have parts 
of a program (could be functions) that keep doing their job while other 
parts do something else on the same data, and what is the best way to do 
this.

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


Re: Parallel(?) programming with python

2022-08-08 Thread Andreas Croci

Thanks for your reply.

On 08.08.22 13:20, Stefan Ram wrote:


   Yes, but this is difficult. If you ask this question here,
   you might not be ready for this.


Indeed.



   I haven't learned it yet myself, but nevertheless tried to
   write a small example program quickly, which might still
   contain errors because of my lack of education.

import threading
import time

def write_to_list( list, lock, event ):
 for i in range( 10 ):
 lock.acquire()
 try:
 list.append( i )
 finally:
 lock.release()
 event.set()
 time.sleep( 3 )

def read_from_list( list, lock, event ):
 while True:
 event.wait()
 print( "Waking up." )
 event.clear()
 if len( list ):
 print( "List contains " + str( list[ 0 ]) + "." )
 lock.acquire()
 try:
 del list[ 0 ]
 finally:
 lock.release()
 else:
 print( "List is empty." )

list = []
lock = threading.Lock()
event = threading.Event()
threading.Thread( target=write_to_list, args=[ list, lock, event ]).start()
threading.Thread( target=read_from_list, args=[ list, lock, event ]).start()


If I understand some things correctly, a "lock" would be something that, 
as the name says, locks, meaning prevents parts of the program from 
executing on the locked resource until ohter parts have finished doing 
their things and have released the lock. If this is correct, it's not 
exactly what I wanted, because this way "parts of the program" would not 
"keep doing their things, while other parts do other things on the same 
data".


I'm in principle ok with locks, if it must be. What I fear is that the 
lock could last long and prevent the function that writes into the list 
from doing so every second. With an FFT on a list that contains a few 
bytes taken every second over one week time (604.800 samples), I believe 
it's very likely that the FFT function takes longer than a second to return.


Then I would have to import all the data I have missed since the lock 
was aquired, which is doable, but I would like to avoid it if possible.




   In basketball, first you must learn to dribble and pass,
   before you can begin to shoot.


Sure.



   With certain reservations, texts that can be considered
   to learn Python are:

"Object-Oriented Programming in Python Documentation" - a PDF file,
Introduction to Programming Using Python - Y Daniel Liang (2013),
How to Think Like a Computer Scientist - Peter Wentworth (2012-08-12),
The Coder's Apprentice - Pieter Spronck (2016-09-21), and
Python Programming - John Zelle (2009).



Thank you for the list. I an currently taking a Udemy course and at the 
same time reading the tutorials on python.org. I hope I will some day 
come to any of the books you suggest (I'm doing this only in my spare 
time and it will take forever).

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


Re: Parallel(?) programming with python

2022-08-08 Thread Andreas Croci

Thank you for your reply.

On 08.08.22 14:55, Julio Di Egidio wrote:


Concurrent programming is quite difficult, plus you better think
in terms of queues than shared data... 


Do you mean queues in the sense of deque (the data structure)? I ask 
because I can see the advantage there when I try to pop data from the 
front of it, but I don't see the sense of the following statement ("than 
shared data"). I mean, I called my structure a list, but it may well be 
a queue instead. That wouldn't prevent it from being shared in the idea 
I described: one function would still append data to it while the other 
is reading what is there up to a certain point and calculate the FFT of it.


 But, an easier and often

better option for concurrent data access is use a (relational)
database, then the appropriate transaction isolation levels
when reading and/or writing.



That would obviusly save some coding (but would introduce the need to 
code the interaction with the database), but I'm not sure it would speed 
up the thing. Would the RDBMS allow to read a table while something else 
is writing to it? I doubt it and I'm not sure it doesn't flush the cache 
before letting you read, which would include a normally slow disk access.


Andreas


Julio


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


Re: Parallel(?) programming with python

2022-08-15 Thread Andreas Croci
I would like to thank everybody who answered my question. The insight 
was very informative. This seems to be one of the few newsgroups still 
alive and kicking, with a lot of knowledgeable people taking the time to 
help others. I like how quick and easy it is to post questions and 
receive answers here as compared to web-based forums (although there are 
some disadvantages too).


I'm implementing some of the ideas received here and I will surely have 
other questions as I go. But the project will take a long time because 
I'm doing this as a hobby during my vacation, that are unfortunately 
about to end.


Thanks again, Community.

On 08.08.22 12:47, Andreas Croci wrote:
tI would like to write a program, that reads from the network a fixed 
amount of bytes and appends them to a list. This should happen once a 
second.


Another part of the program should take the list, as it has been filled 
so far, every 6 hours or so, and do some computations on the data (a FFT).


Every so often (say once a week) the list should be saved to a file, 
shorthened in the front by so many items, and filled further with the 
data coming fom the network. After the first saving of the whole list, 
only the new part (the data that have come since the last saving) should 
be appended to the file. A timestamp is in the data, so it's easy to say 
what is new and what was already there.


I'm not sure how to do this properly: can I write a part of a program 
that keeps doing its job (appending data to the list once every second) 
while another part computes something on the data of the same list, 
ignoring the new data being written?


Basically the question boils down to wether it is possible to have parts 
of a program (could be functions) that keep doing their job while other 
parts do something else on the same data, and what is the best way to do 
this.


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


Performance issue with CPython 3.10 + Cython

2022-10-04 Thread Andreas Ames
-10-04 10:41:16|INFO|__main__   |Execution loop 1600 done. GC
> counts = (381, 9, 3); 1 second of application time corresponds to
> 0.2541334629058838 seconds real time.
> 2022-10-04 10:41:19|INFO|__main__   |Execution loop 1700 done. GC
> counts = (381, 9, 3); 1 second of application time corresponds to
> 0.26812195777893066 seconds real time.
> 2022-10-04 10:41:21|INFO|__main__   |Execution loop 1800 done. GC
> counts = (381, 9, 3); 1 second of application time corresponds to
> 0.28777456283569336 seconds real time.
> 2022-10-04 10:41:24|INFO|__main__   |Execution loop 1900 done. GC
> counts = (381, 9, 3); 1 second of application time corresponds to
> 0.3005337715148926 seconds real time.
> 2022-10-04 10:41:28|INFO|__main__   |Execution loop 2000 done. GC
> counts = (381, 9, 3); 1 second of application time corresponds to
> 0.30992960929870605 seconds real time.
> 2022-10-04 10:41:31|INFO|__main__   |Execution loop 2100 done. GC
> counts = (381, 9, 3); 1 second of application time corresponds to
> 0.32058119773864746 seconds real time.
> 2022-10-04 10:41:34|INFO|__main__   |Execution loop 2200 done. GC
> counts = (381, 9, 3); 1 second of application time corresponds to
> 0.33020949363708496 seconds real time.
> 2022-10-04 10:41:37|INFO|__main__   |Execution loop 2300 done. GC
> counts = (381, 9, 3); 1 second of application time corresponds to
> 0.34426307678222656 seconds real time.
> 2022-10-04 10:41:41|INFO|__main__   |Execution loop 2400 done. GC
> counts = (381, 9, 3); 1 second of application time corresponds to
> 0.3585126338965 seconds real time.
> 2022-10-04 10:41:45|INFO|__main__   |Execution loop 2500 done. GC
> counts = (381, 9, 3); 1 second of application time corresponds to
> 0.3664553165435791 seconds real time.
> 2022-10-04 10:41:48|INFO|__main__   |Execution loop 2600 done. GC
> counts = (381, 9, 3); 1 second of application time corresponds to
> 0.3767662048339844 seconds real time.
> 2022-10-04 10:41:52|INFO|__main__   |Execution loop 2700 done. GC
> counts = (381, 9, 3); 1 second of application time corresponds to
> 0.39760732650756836 seconds real time.
> 2022-10-04 10:41:56|INFO|__main__   |Execution loop 2800 done. GC
> counts = (381, 9, 3); 1 second of application time corresponds to
> 0.42221736907958984 seconds real time.
> 2022-10-04 10:42:01|INFO|__main__   |Execution loop 2900 done. GC
> counts = (381, 9, 3); 1 second of application time corresponds to
> 0.4237234592437744 seconds real time.


Thanks in advance,

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


Re: Performance issue with CPython 3.10 + Cython

2022-10-07 Thread Andreas Ames
Answering to myself, just for the records:

1. The culprit was me. As lazy as I am, I have used f-strings all over the
place in calls to `logging.logger.debug()` and friends, evaluating all
arguments regardless of whether the logger was enabled or not.  Replacing
these f-strings by regular printf-like format strings solved the issue.
Now the application bowls happily along, consistently below 0.02 seconds
per second application time.
2. Valgrind + callgrind is an awesome toolchain to spot performance issues,
even on VMs.


Am Di., 4. Okt. 2022 um 11:05 Uhr schrieb Andreas Ames <
andreas.0815.qwe...@gmail.com>:

> Hi all,
>
> I am wrapping an embedded application (, which does not use any dynamic
> memory management,) using Cython to call it from CPython.  The wrapped
> application uses a cyclic executive, i.e. everything is done in the
> input-logic-output design, typical for some real-time related domains.
> Consequentially, every application cycle executes more or less the very
> same code.  As I am still in a prototyping stadium, the wrapped process is
> completely CPU-bound, i.e. except of some logging output there is no I/O
> whatsoever.
>
> During one second of "application time", I am doing exactly 120 calls into
> the application through three Cython-wrapped API functions.  The
> application uses some platform-dependent APIs, which I have also wrapped
> with Cython, so that there are numerous callbacks into the Python realm per
> call into the application. What I am observing now, is that the performance
> per "application second" decreases (remember: executing code that does the
> same thing on every cycle) and extending the number of loop iterations does
> not seem to cause any bound to this decrease.  In the log ouput below, you
> can see the GC counts, which look innocent to me.  The "real time" is
> measured using "time.time()". The "top" utility does not suggest any memory
> leak either.  I am developing on WSL2, but I have checked that this
> performance effect also happens on physical machines.  Right now, I am
> staring at "kcachegrind", but I have no idea, how to determine time series
> for the performance of functions (I am not looking for those functions,
> which need the most time, but for those, which consume more and more
> execution time).
>
> One more thing to look for could be memory fragmentation, but before that
> I would like to ask the experts here for their ideas and experiences and/or
> for tools, which could help to find the culprit.
>
> 2022-10-04 10:40:50|INFO|__main__   |Execution loop 0 done. GC
>> counts = (381, 9, 3); 1 second of application time corresponds to
>> 0.06862711906433105 seconds real time.
>> 2022-10-04 10:40:51|INFO|__main__   |Execution loop 100 done. GC
>> counts = (381, 9, 3); 1 second of application time corresponds to
>> 0.08224177360534668 seconds real time.
>> 2022-10-04 10:40:52|INFO|__main__   |Execution loop 200 done. GC
>> counts = (381, 9, 3); 1 second of application time corresponds to
>> 0.08225250244140625 seconds real time.
>> 2022-10-04 10:40:53|INFO|__main__   |Execution loop 300 done. GC
>> counts = (381, 9, 3); 1 second of application time corresponds to
>> 0.10176873207092285 seconds real time.
>> 2022-10-04 10:40:54|INFO|__main__   |Execution loop 400 done. GC
>> counts = (381, 9, 3); 1 second of application time corresponds to
>> 0.10900592803955078 seconds real time.
>> 2022-10-04 10:40:55|INFO|__main__   |Execution loop 500 done. GC
>> counts = (381, 9, 3); 1 second of application time corresponds to
>> 0.12233948707580566 seconds real time.
>> 2022-10-04 10:40:56|INFO|__main__   |Execution loop 600 done. GC
>> counts = (381, 9, 3); 1 second of application time corresponds to
>> 0.14058256149291992 seconds real time.
>> 2022-10-04 10:40:58|INFO|__main__   |Execution loop 700 done. GC
>> counts = (381, 9, 3); 1 second of application time corresponds to
>> 0.14777183532714844 seconds real time.
>> 2022-10-04 10:40:59|INFO|__main__   |Execution loop 800 done. GC
>> counts = (381, 9, 3); 1 second of application time corresponds to
>> 0.15729451179504395 seconds real time.
>> 2022-10-04 10:41:01|INFO|__main__   |Execution loop 900 done. GC
>> counts = (381, 9, 3); 1 second of application time corresponds to
>> 0.17365813255310059 seconds real time.
>> 2022-10-04 10:41:03|INFO|__main__   |Execution loop 1000 done. GC
>> counts = (381, 9, 3); 1 second of application time corresponds to
>> 0.17772984504699707 seconds real time.
>> 2022-10-04 10:41:05|INFO|__main__   |Exec

Re: Find the path of a shell command

2022-10-17 Thread Andreas Eder
On Mi 12 Okt 2022 at 05:00, Paulo da Silva 
 wrote:

> The simple question: How do I find the full path of a shell command
> (linux), i.e. how do I obtain the corresponding of, for example,
> "type rm" in command line?
>
> The reason:
> I have python program that launches a detached rm. It works pretty well
> until it is invoked by cron! I suspect that for cron we need to specify
> the full path.
> Of course I can hardcode /usr/bin/rm. But, is rm always in /usr/bin?
> What about other commands?

Why not just use os.unlink ?

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


built-in pow() vs. math.pow()

2023-03-30 Thread Andreas Eisele
I sometimes make use of the fact that the built-in pow() function has an 
optional third argument for modulo calculation, which is handy when dealing 
with tasks from number theory, very large numbers, problems from Project Euler, 
etc. I was unpleasantly surprised that math.pow() does not have this feature, 
hence "from math import *" overwrites the built-in pow() function with a 
function that lacks functionality. I am wondering for the rationale of this. 
Does math.pow() do anything that the built-in version can not do, and if not, 
why is it even there?
Thanks in advance for any enlightening comment on this.
Best regards, Andreas
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: built-in pow() vs. math.pow()

2023-04-03 Thread Andreas Eisele
Andreas Eisele schrieb am Donnerstag, 30. März 2023 um 11:16:02 UTC+2:
> I sometimes make use of the fact that the built-in pow() function has an 
> optional third argument for modulo calculation, which is handy when dealing 
> with tasks from number theory, very large numbers, problems from Project 
> Euler, etc. I was unpleasantly surprised that math.pow() does not have this 
> feature, hence "from math import *" overwrites the built-in pow() function 
> with a function that lacks functionality. I am wondering for the rationale of 
> this. Does math.pow() do anything that the built-in version can not do, and 
> if not, why is it even there? 
> Thanks in advance for any enlightening comment on this. 
> Best regards, Andreas

Thanks a lot to all of you for the insightful replies! 
I now understand why math.pow() behaves the way it does and whoever tells me I 
should have read the doc of the math module before using it is 100% on point. 
BTW, there is another difference: built-in pow() deals with complex arguments, 
while functions in math won't accept them at all.
I also agree with the warning that importing * from any module is generally a 
bad idea, and I normally would not do it.  But here I had written a little tool 
that evaluates an expression given on the command line, and in this case having 
math functions available without further ado is very convenient, so it seemed 
appropriate to make an exeption to this rule.
I ended up assigning the built-in pow function to a different name before 
importing the math module, which is a good way to keep both variants accessible.
Best regards, and thanks again, Andreas
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Call for Assistance

2016-08-11 Thread Andreas Röhler



On 12.08.2016 06:48, Lawrence D’Oliveiro wrote:

On Wednesday, August 10, 2016 at 3:42:39 AM UTC+12, Reto Brunner wrote:

What on earth isn't "free" enough about

You are free to:
Share — copy and redistribute the material in any medium or format

No you are not. A court has ruled 

 quite clearly that “non-commercial” means PERSONAL USE ONLY, no redistribution or 
republication.


The court ruled at the special case. The institution in question is paid 
by all germans due to a kind of fea imposed - "Rundfunkbeitrag". 
Everyone owning or renting an object in Germany has to pay to them - 
without regard if they uses that media or not. If you have to pay to 
someone, you would not consider that relation non-commercial.

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


Re: Distinction between “class” and “type”

2016-05-14 Thread Andreas Röhler



I suspect that one could produce a class that is not a type,


Say: has not a complete type definition. Think of type for example with 
the distinction of strings and numbers.


Types start from low level units. A class definition must know about 
strings and numbers, it inherits this knowledge from the syntax of 
language. Even an empty class must be constructed.


Types may be composed resp derived from other types. Any class finely 
will constitute a type composed by its body.


In case an definition may used for example equally for addition or 
string-concatenation, ambiguity constitutes a composed resp. derived 
type by themselves.


In general terms: the type tells the structure of arguments it receives 
alongside with the way, it deals with them.




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


Re: Operator Precedence/Boolean Logic

2016-06-22 Thread Andreas Röhler



On 23.06.2016 06:47, Lawrence D’Oliveiro wrote:

On Thursday, June 23, 2016 at 3:12:52 PM UTC+12, Larry Hudson wrote:

On 06/22/2016 12:42 AM, Lawrence D’Oliveiro wrote:

* boolean operators don’t have to operate on boolean values. The
   language spec
   
   says:

 “...the following values are interpreted as false: False, None, numeric
 zero of all types, and empty strings and containers (including strings,
 tuples, lists, dictionaries, sets and frozensets). All other values are
 interpreted as true.”

I feel that’s a needlessly complicated rule. It would have been simpler if
boolean operators (and conditional expressions like in if-statements and
while-statements) only allowed values of boolean types. But that’s one of
the few warts in the design of Python...

Wart??  I *strongly* disagree.  I find it one of the strengths of Python,
it enhances Python's expressiveness.

Tightening it up would rule out a whole class of common errors, from misunderstanding (or 
forgetting) the rule about what exactly gets interpreted as true and what as false 
 
.


Indeed, why should the result of 4 - 4 have a different truth-value than 
4 - 3 ?
This implementation seems to be a legacy from languages without boolean 
types.

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


Re: Operator Precedence/Boolean Logic

2016-06-23 Thread Andreas Röhler



On 23.06.2016 09:05, Steven D'Aprano wrote:

On Thursday 23 June 2016 16:34, Andreas Röhler wrote:


Indeed, why should the result of 4 - 4 have a different truth-value than
4 - 3 ?

Because 4-4 is zero, which is "nothing",


Hmm,  water freezes at zero degree celsius, because there is no temperature?


  while 4-3 is one, which is
"something".

You might as well ask why False and True have different truth values.
Ironically, in a manner of speaking you *did* ask that, since 4-3 == True and
4-4 == False.




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


Re: Operator Precedence/Boolean Logic

2016-06-23 Thread Andreas Röhler



On 23.06.2016 10:17, Antoon Pardon wrote:

Op 23-06-16 om 09:05 schreef Steven D'Aprano:

On Thursday 23 June 2016 16:34, Andreas Röhler wrote:


Indeed, why should the result of 4 - 4 have a different truth-value than
4 - 3 ?

Because 4-4 is zero, which is "nothing", while 4-3 is one, which is
"something".

No zero is not nothing. If zere is nothing and an empty list is nothing,
I would expect zero to be an empty list or that they could be used 
interchangebly.




There is a fundamental diff between zero and emptiness.

Zero is just a relation in the realm of integers. It tells being in the 
midst between positiv and negativ infinity.
Number one tells being one unit towards positiv infinity in relation to 
negativ infinity. And so on.


Whilst emptiness tells about non-existence.
--
https://mail.python.org/mailman/listinfo/python-list


Re: Operator Precedence/Boolean Logic

2016-06-23 Thread Andreas Röhler



On 23.06.2016 11:17, Steven D'Aprano wrote:

[ ... ]
We can derive arithmetic from set theory.


IMO not, resp. not really. But that would make a another item, pretty 
off-topic from Python.


Should you know a place where to continue, would like to follow up.

Thanks BTW.


  Zero is very special: it is defined
as the empty set:

0: {}

The successor of zero (namely, one) is the set of all empty sets:

1: {{}}

Two is the set of zero and one:

2 = {{}, {{}}}

and so forth.





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


Re: Operator Precedence/Boolean Logic

2016-06-23 Thread Andreas Röhler



On 23.06.2016 11:46, Marko Rauhamaa wrote:


Ridiculous? It was this line of thinking that led Paul Dirac to predict
the existence of antimatter.


Marko


Yeah. Maybe we could construct examples already using antagonistic 
charges of electrons?

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


Re: Operator Precedence/Boolean Logic

2016-06-23 Thread Andreas Röhler



On 23.06.2016 14:08, Antoon Pardon wrote:

Op 23-06-16 om 13:45 schreef Chris Angelico:

On Thu, Jun 23, 2016 at 7:23 PM, Antoon Pardon
 wrote:

I don't care. In modern mathematics, zero is usaly defined as the
empty set. The empty set contains nothing, but it isn't nothing
itself. Otherwise the empty set would be the same as the set
containing the empty set, since they both would contain the same,
being nothing.

Zero is *the cardinality of* the empty set. The set containing the
empty set has a cardinality of 1.

In modern set theory where the integers are defined as specific kind
of sets, zero *is* the empty set.



Modes are like waves. If one wave arrives being "modern", lets watch out 
for the next.


There not just one set-theory, math is neither revealed nor received on 
some mount - even if the notion of truth has some theological 
connotations ;)

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


Re: Can math.atan2 return INF?

2016-06-30 Thread Andreas Röhler



On 30.06.2016 03:33, Lawrence D’Oliveiro wrote:


So you see, like it or not, we are drawn to the conclusion that there *was* 
indeed something before our particular Big Bang.


That's linear like the Big Bang theorie. What about assuming something 
beyond our notion of time and space, unknown still?

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


Re: Can math.atan2 return INF?

2016-06-30 Thread Andreas Röhler



On 30.06.2016 10:24, Steven D'Aprano wrote:

On Thursday 30 June 2016 12:13, Rustom Mody wrote:

[ ... ]
Besides, the whole point of science is to develop objective, rational reasons
to believe things.


Science is not about believing, but about models.
Believing is important to make the career of a scientist maybe, it's for 
people outside.

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


Re: Can math.atan2 return INF?

2016-06-30 Thread Andreas Röhler



On 30.06.2016 10:24, Steven D'Aprano wrote:

On Thursday 30 June 2016 12:13, Rustom Mody wrote:


The irrational and emotional psychological forces that inspire mathematicians
can make interesting reading, but they have no relevance in deciding who is
write or wrong.


Hmm, so math is not inspired by solving real world problems, for example 
in physics or big-data?




  No numbers are real.


Numbers express relations, which are represented as symbols. So far they 
are real, as math exists, the human mind exists.


We don't have any natural numbers, assume Kronecker made a joke. 
"Natural numbers" is the most misleading term in the field maybe.


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


Re: Can math.atan2 return INF?

2016-06-30 Thread Andreas Röhler



On 30.06.2016 11:42, Lawrence D’Oliveiro wrote:

On Thursday, June 30, 2016 at 9:31:29 PM UTC+12, Andreas Röhler wrote:


Science is not about believing, but about models.

The nice thing about science is, it works even if you don’t believe in it.



Thats it!
--
https://mail.python.org/mailman/listinfo/python-list


Re: extract PDF pages

2005-10-13 Thread Andreas Lobinger
Aloha,

David Isaac wrote:
> I am looking for a Python solution.
> Just for PDF page extraction.
> Any hope?

With python, there's always hope.
http://sourceforge.net/projects/pdfplayground

In the CVS (sorry no distribution at the time) you'll find
an example page-extract.
http://cvs.sourceforge.net/viewcvs.py/pdfplayground/ppg/Exp/page-extract.py?rev=1.1&view=markup

pdfplayground is limited at the moment to PDF <= 1.4.
If you want to do more with .pdfs you'll probably need at least
a basic understanding of the PDF specification. pdfplayground
is focused at low-level .pdf (by implementation resources...).

Thomas Lotze is also preparing a pdf reader/writer project:
http://svn.thomas-lotze.de/PDFSpec/

So is David Boddie:
http://www.boddie.org.uk/david/Projects/Python/pdftools

Wishing a happy day
LOBI
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Abstract Methods & Abstract Class

2005-10-19 Thread Andreas Kostyrka
On Thu, Oct 20, 2005 at 12:05:05PM +0530, Iyer, Prasad C wrote:
> 
> Do we have something like abstract methods & Abstract class.
> 
> So that my class would just define the method. And the implementation
> would be defined by somebody else.

class AbstractBase:
def method(self):
raise TypeError("abstract method called")

But basically, Python does not have abstract methods, and usually doesn't
need them.

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


tachometer diagram

2005-10-31 Thread Andreas Kaiser
Hello,

I'am searching for a python solution for display a tachometer diagram.
I prefer a solution for wxPython.
The plot libraries I've found do not implement this diagram type.
Any hints welcome!

Thanks
Andreas

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


Re: tachometer diagram

2005-10-31 Thread Andreas Kaiser
Hello Jorge,

I can change my mind, sorry. The target OS for this app is Win. When
pyQt4 is available, I will check QT.

Andreas

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


Re: tachometer diagram

2005-10-31 Thread Andreas Kaiser
> I can change my mind, sorry.
Should be: I _can't_ change ...

Andreas

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


Re: tachometer diagram

2005-11-02 Thread Andreas Kaiser
Hi Franz,

you're right! Andrea (the developer of these widgets) sends me this
link about the wxPython ML.
Thanks.

Andreas

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


[Subprocess/Windows] subprocess module under Windows 98

2005-11-02 Thread Andreas Jung


Hi,

I am using subprocess.Popen() to start Java processes (converters) from 
within Zope under Windows 98 (sorry, we have to support the platform). The 
call looks like this:



P = Popen('java.exe arguments...', stdout=PIPE, stderr=PIPE, 
stdin=open('nul:')).


stdin=open('nul:') is required to make Popen() actually running under 
Windows 98 (stdin=None works fine on XP).


However for every Popen() call Windows 98 opens an empty DOS box that 
disappear after completion of the converter process. The Popen() has some
'startupinfo' and 'creationflags' attributes but I could not find any 
documentation. Is there a way to suppress the DOS boxes somehow using these 
attributes or is there another way to get rid of them?


Thanks in advance,
Andreas



pgpwXZAww91hx.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: subprocess module under Windows 98

2005-11-02 Thread Andreas Jung



--On 2. November 2005 08:48:24 -0800 Ernesto <[EMAIL PROTECTED]> wrote:


This worked for me on XP... not sure for 98...

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/409002


Thanks, this works!

Andreas

pgpeWK0kWa6KX.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Addressing the last element of a list

2005-11-08 Thread Andreas Lobinger
Aloha,

[EMAIL PROTECTED] wrote:
> Isn't there an easier way than
> lst[len(lst) - 1] = ...
lst[-1] = ...

Wishing a happy day
LOBI
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Dynamic Link Library

2005-12-05 Thread Andreas Kostyrka
Am Montag, den 05.12.2005, 21:30 -0500 schrieb Ervin J. Obando:
> Hi everyone,
> 
> Apologies if my question is a bit novice-ish. I was wondering if there 
> was a way of creating a Dynamic Link Library with Python.

Probably yes. But why would you want to do that? Actually the way would
be to create an interface module with public cdef'ed functions in Pyrex,
and embed Python in your DLL.

But it's certainly not something you want to try when you ask this kind
of questions, it's a headache.

Andreas

> 
> Please provide any answers you may have.
> 
> Warmest Regards,
> 
> musicdev
> 


signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil
-- 
http://mail.python.org/mailman/listinfo/python-list

Point of Sale

2005-01-27 Thread Andreas Pauley
Hi,
My company has given me a rather cool project:
I have to provide them with an open-source python-based point-of-sale / 
cash register system that can integrate with their existing ERP backend.

The project will include development to ensure that the features they 
require are included in the open-source POS system.

Can you recommend anything that I can use?
Regards,
Andreas
--
http://mail.python.org/mailman/listinfo/python-list


Re: Point of Sale

2005-01-27 Thread Andreas Pauley

On Thu, 27 Jan 2005, Cameron Laird wrote:
In article <[EMAIL PROTECTED]>,
Andreas Pauley  <[EMAIL PROTECTED]> wrote:
Hi,
My company has given me a rather cool project:
I have to provide them with an open-source python-based point-of-sale /
cash register system that can integrate with their existing ERP backend.
The project will include development to ensure that the features they
require are included in the open-source POS system.
Can you recommend anything that I can use?
.
.
.
Research.  I think you're expecting an answer of the "I used
open-source openPOS project, and it worked great for me", but
I suspect all that is premature.  What does POS mean to you?
What are your platform constraints?  Does your company have
expectations about how POS will work?  What access (CORBA?
RMI?  SOAP? ...) is there to the ERP?
Very well, I guess a little more detail would help.
Platform: Cross-platform, although deployment would typically be done on 
Linux.
My company typically expects that each POS station will have it's own 
database with all sales items and other info on it.
The maintenance of sales items, prices etc. should however be done at a 
central location, and then be replicated to each POS station.
The reason for this is that we will typically deploy such a system in 
deep-dark-africa where stable network connectivity cannot be taken for 
granted.
If the network is down each POS station should still be able to function 
without interruption.

These requirements is probably not available in a typical POS system, but 
I'm hoping for a general POS front-end for which I can develop a custom 
backend to plug in.
At the moment the current POS system uses an inhouse developed message 
queing system to communicate with the ERP/Retail backend. A POS station 
submits each transaction (and other relevant messages) to a local queue, 
from where it is sent to the back-end system. If the network is down the 
messages just stay queued until the network is back up again.
The central backend system uses the same queing technique to submit price 
updates etc. to each POS station.

I'm not sure what protocol will be used to communicate with the backend.
I might have SOAP available.
The backend is written using Appservers from Progress Software Corporation 
(a proprietary database company).
The Progress developers would probably be willing to help, so I'm 
relatively positive that we'll be able to figure out a solution there.

The user interface for the current system is character-based.
For the new POS we should ideally be able to use different user-interfaces 
that all access the same business logic, although I would primarily focus 
on a non-mouse driven GUI interface.

I hope the above answers your question, if not feel free to ask again.
Regards,
Andreas Pauley
--
http://mail.python.org/mailman/listinfo/python-list


Re: Point of Sale

2005-01-27 Thread Andreas Pauley

On Thu, 27 Jan 2005, Peter Hansen wrote:
Andreas Pauley wrote:
My company has given me a rather cool project:
I have to provide them with an open-source python-based point-of-sale / 
cash register system that can integrate with their existing ERP backend.
Do you have information about the interface to the ERP back end?
It could be anything just about anything...
See my reply to Cameron.

The project will include development to ensure that the features they 
require are included in the open-source POS system.
I read that as "will include automated acceptance tests", but perhaps
you meant something else?
Actually I just mean that I'm not looking for a 100% feature-fit, if I get 
a 70% fit I'll jump in and develop the other 30%.


Can you recommend anything that I can use?
There's a good chance you'll need to use PySerial, if the
cash registers are connected via RS-232, but beyond that
there's not much to say without more info.  I believe I
heard somebody talking about a Python POS system before
in this newsgroup, but I'm not sure: check the archives?
Thanks, I'll keep PySerial in mind.
Up to now I've googled a bit, and looked at Sourceforge projects.
(I also did a search on the 51664 messages in my local Python-list folder)
At the moment I found a POS in GNU Enterprise, a project named "custom" 
and another project named "Auto Auction".
I'm not sure what the features of each system are, I'm busy checking them 
out one by one.
Then there's also 3 or 4 Python systems which haven't released any files 
yet.
Currently I'm evaluating GNU Enterprise.

Regards,
Andreas
--
http://mail.python.org/mailman/listinfo/python-list


  1   2   3   4   5   6   7   >