Re: subprocess problem

2017-02-09 Thread Günther Dietrich
Am 09.02.17 um 18:16 schrieb Andreas Paeffgen:
> I guess which does not return an error code.

In fact, id does return a return code. Here an example:

| honk:~ gdie$ which bash; echo $?
| /bin/bash
| 0
| honk:~ gdie$ which wzlbrmpf; echo $?
| 1

It is 0 on success, 1 for a failure. Exactly the result I would expect
from an unixoid program.


On Ubuntu 16.04, 'man which' tells of three possible exit states: 0, 1
and 2.
On Mac OS, the return codes are not documented. It seems, there are only
0 (success) and 1 (failure).

Normally, on unixoid operating systems, return code 0 indicates success,
anything else non-success, failure or error.


> If it does not find
> anything, the return is just blank. If it finds something, the path is
> returned.

That is the result on STDOUT. It is _not_ the return code!


> So the change of code did not help, because there is just no error message.

Do you expect an error message, or a return code? An error message would
-- normally -- appear on STDERR.


> Could there be a $path problem in the subprocess started inside the binary?

That's for sure. I already had this problem with py2exe. I solved it by
passing a directory containing a suitable PATH entry to the env argument
of subprocess.Popen(). Problem gone.


If you call 'python myscript.py' on the shell command line, the python
script will inherit a copy the shell's environment.
If you start a frozen python script, there is no shell's environment, it
could inherit. It is up to the tool you used to freeze the script
(cx_freeze, py2exe, etc.), which environment contents it will see.



Best regards,

Günther

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


Re: Mac vs. Linux for Python Development

2014-02-23 Thread Günther Dietrich
twiz  wrote:

>I've been developing with python recreationally for a while on Ubuntu but will 
>soon be transitioning to full-time python development.  I have the option of 
>using a Mac or Ubuntu environment and I'd like to hear any thoughts on the 
>pros and cons of each.

I've been working with Windows, Unix/Linux (X) and Max OS since 1989. In 
my experience the GUI of Mac OS is the most user friendly of the the 
three.


>Specifically, how's the support for numpy and scipy?  
>How are the IDEs?
>
>Since I generally like working with a Mac, I'd like to hear if there are any 
>significant downsides to python dev on OsX.  

Eclipse and the PyDev and MercurialEclipse plug-ins are available for 
Windows, Linux and Mac OS.
So, if I had the choice, I would go with the Mac.



Best regards,

Günther
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Text-to-Sound or Vice Versa (Method NOT the source code)

2013-05-25 Thread Günther Dietrich
Rakshith Nayak  wrote:

>Always wondered how sound is generated from text. Googling couldn't help. Devs 
>having knowledge about this could provide, the information, Links, URLs or 
>anything that could help. 

Perhaps try 'text to speech' instead of 'text to sound'?



Best regards,

Günther
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I hate you all

2013-04-06 Thread Günther Dietrich
terminato...@gmail.com wrote:

>[...]
>> The "def" line has four spaces.  The "for" line then has a hard tab.
>> This is ambiguous.  If the hard tab is assumed to have a width of four
>> spaces, then they are at the same indentation level.  If it is assumed
>> to have a width of eight spaces, then they are not.
>[...]
>
>The correct tab stop positions have always been at 8 character columns apart.
>The "ambiguity" was introduced by editors that do not follow the default value 
>set in hardware like printers or used by consoles and terminal emulators.
>
>And now python forces me out of using any tab characters at all. I believe I 
>should still have a choice, python should at lest give an option to set tab 
>size, if the default of 8 is ambiguous now.

You know the Unix command 'expand'? If you used tabs representing eight 
columns consequently, use expand on your python scripts to convert tabs 
to spaces before running them.



Best regards,

Günther
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help accessing COM .dll from Python

2012-12-01 Thread Günther Dietrich
Steve Simmons  wrote:

>
>  
>
>
>  
>  
>First time post -
>be gentle with me :-)
>  
>I am trying to write a Python script to
>  access a scanning device.  I
>  have an SDK for the size="-1">scanner but the documentation is a   size="-1">bit limited and the supplier doesn't support
>  Python (but Python is
>  the best option for me in the
>current 
>circumstances). >
>  
>  
>  The SDK revolves around a .dll file that   size="-1">is described as a 'COM Object'
>but the text also implies that it can be ac  size="-1">cessed directly - "If you don’t use the COM
>  interface in your application and use the SDK files
>  directly like in VC++ then you don’t need to install
>  these files on the destination computer".  If I look
>  inside the .dll (thanks PE  size="-1"> Explorer!), I see DllCanUnload,
>  DllGetClassObject, DllRegisterServer and
>  DllUnregisterServer in the 'Export' view.  If I
>  look at the 'Import' view, I can
>see the names of a bunch of size="-1">.dll files and the
>names of the functions/methods
>I want to call.  So I concluded that  
>>  size="-1">size="-1">size="-1">  size="-1">  size="-1">size="-1">size="-1">size="-1">DllGetClassObject
>  would be my
>
>friend.t>
>
>  
>  However, I've read
>  various tutorials on using .dll and COM (ctypes,
>  comtypes, and the Python documentation) and I've
>  ended up more confused than when
>I started.  I expected to be
>  using COM but all the examples seem to revolve
>  around automating excel or out  size="-1">look.
>
>I'd be really grateful for
>  some hints on what direction Isize="-1"> should be headed
>  and a pointer to a relevant 
>tutorial.
>
>  
>  Simmo
>
>  
>

A newsreader is not an HTML reader (aka web browser). Please post your 
question in plain text.



Best regards,

Günther
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: try/except KeyError vs "if name in ..."

2012-10-06 Thread Günther Dietrich
Manuel Pégourié-Gonnard  wrote:

>Hi,
>I was looking at the example found here [1] which begins with:
>
>[1] http://docs.python.org/py3k/library/imp.html#examples
>
>def __import__(name, globals=None, locals=None, fromlist=None):
># Fast path: see if the module has already been imported.
>try:
>return sys.modules[name]
>except KeyError:
>pass
>
>I was wondering if the formulation
>
>if name in sys.modules:
>return sys.modules[name]
>
>would be equivalent. IOW, is using try/except here only a matter of
>style or a necessity?

Somewhere I read a text regarding 'try:' versus 'if'. If you take the 
probabitility into consideration, how many times the test will fail or 
succeed, there are two possibilities:
- If the test will fail only on very rare occasions: Use 'try:'. When 
the statement(s) in the try-path succeed, the try:/except: construct 
will not consume additional execution time (not even for the test). The 
statements will just be executed as they are. Only in the (rare) case of 
failure, the exception handling will take additional execution time (a 
considerably big amount). The fact, that in python it is not named 
'error handling', but 'exception handling' reflects this. The failure 
should be the exception, also in matters of occurrence.
- If the relation between success and failure is not predictable, or if 
the case of failure will be frequent, use 'if'. The failure of a 'try:' 
gives you a penalty in form of consumption of a high amount of execution 
time. So, in these constellations, it is better to accept the relatively 
small amount of execution time taken by the explicit test.

Obviously, you can use 'try:' only, if there is the possibility to 
produce an exception on failure. In the other cases you must use the 
explicit test by 'if'.


>I'm suspecting that maybe, in multithreaded environments, the second
>option may be subject to a race condition, if another thread removes
>name frome sys.modules between the if and the return, but as I'm not
>very familiar (yet) with Python threads, I'm not sure it is a real
>concern here.

Your idea sounds reasonable, but I also am not yet familiar with threads.


>And maybe there are other reasons I'm completely missing for prefering
>EAFP over LBYL here?

One reason might be what I described above.



Best regards,

Günther
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Reading properties file in Python, except using ConfigParser()

2012-10-05 Thread Günther Dietrich
justmailha...@gmail.com wrote:

>How to read properties file in Python? I found ConfigParser() but it has a 
>'section' limitation, so looking for other alternatives.

Have a look at PyYAML.



Best regards,

Günther
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: datetime issue

2012-09-16 Thread Günther Dietrich
In article ,
 Νικόλαος Κούρας  wrote:

[...]

>also it would be nice if datetime.datetime.now(GMT+2) can be used.

In , one of 
the first answers to your question you were pointed to pytz. This module 
does exactly what you ask for:

>>> import datetime
>>> import pytz
>>> greek_date = datetime.datetime.now(pytz.timezone('Europe/Athens'))
>>> greek_date
>>> print(greek_date)

If you do a help(pytz), obviously after having imported pytz, you will 
get some information about the module. At the end of this help, there 
are some attributes listed. One of them is all_timezones. Guess what it 
contains?



Best regards,

Günther




PS: I didn't know pytz yet. But it took me just five minutes of reading 
the datetime documentation and trying pytz.timezone(), to get a working 
example.
So I don't understand, why you didn't follow the proposal of trying 
pytz, but claimed, it wouldn't work.
Can you explain, why ist doesn't work for you rsp. what is the error 
when it doesn't work?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Invalid syntax error

2012-03-10 Thread Günther Dietrich
In article 
<46758542-1bd6-43fe-8e80-bcf14b7d8...@pi6g2000pbc.googlegroups.com>,
 sl33k  wrote:

>I'm trying project euler problem 3 and I've hit the wall with this
>error. What could be the problem here?
>
> l=[]
 num=600851475143
 i=1
 while i<=num:
>... if num%i==0:
>... l.append(i)
>... i+=1
>... print max(l)
>  File "", line 5
>print max(l)
>^
>SyntaxError: invalid syntax

You have to insert an empty line after the end of the while loop (before 
the print command), so that the interpreter can run and finish the loop 
before it is to print the result.



Best regards,

Günther
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: mutually exclusive arguments to a constructor

2011-12-30 Thread Günther Dietrich
Adam Funk  wrote:

>Suppose I'm creating a class that represents a bearing or azimuth,
>created either from a string of traditional bearing notation
>("N24d30mE") or from a number indicating the angle in degrees as
>usually measured in trigonometry (65.5, measured counter-clockwise
>from the x-axis).  The class will have methods to return the same
>bearing in various formats.
>
>In Java, I would write two constructors, one taking a single String
>argument and one taking a single Double argument.  But in Python, a
>class can have only one __init__ method, although it can have a lot of
>optional arguments with default values.  What's the correct way to
>deal with a situation like the one I've outlined above?

You can determine the type of the input data by using isinstance() and 
take the appropriate actions depending on this decision:

>>> class MyClass(object):
... def __init__(self, input_data):
... if isinstance(input_data, basestring):
... print "Do actions for string type input"
... elif isinstance(input_data, float):
... print "Do actions for float type input"
... def get_output_data(self):
... return "output data"
... 
>>> a = MyClass("String")
Do actions for string type input
>>> b = MyClass(15.9)
Do actions for float type input



Best regards,

Günther
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: calculate difference between two timestamps [newbie]

2011-12-17 Thread Günther Dietrich
nukeymusic  wrote:

>I'm trying to calculate the difference in seconds between two

[...]

>>> import datetime
>>> date1 = datetime.datetime.strptime("Dec-13-09:47:12", "%b-%d-%H:%M:%S")
>>> date2 = datetime.datetime.strptime("Dec-13-09:47:39", "%b-%d-%H:%M:%S")
>>> delta = date2 - date1
>>> delta_seconds = (delta.days * 60 * 60 * 24) + delta.seconds + 
>>> ((delta.microseconds + 50) / 100)

For very big time differences you should consider to use the Decimal 
arithmetics (standard module Decimal) instead of integer arithmetics 
for the last line.
If you are sure, that you don't use fractional seconds, you can omit
the part with 'delta.microseconds'.



Best regards,

Günther
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Windows Extensions for Mac

2011-08-20 Thread Günther Dietrich
In article ,
 Chris Rebert  wrote:

>On Fri, Aug 19, 2011 at 1:02 PM, johnny.venter  wrote:
>>
>> Hello, I am looking for the Python Windows Extensions to see if they can be 
>> installed on a Mac.THanks.
>
>Your request is nonsensical.

That's not completely true.


>pywin32 wraps the Windows API libraries.
>Mac OS X is not Windows; it does not implement the Windows API. Thus,
>there is nothing for pywin32 to wrap on a Mac.

Again: Not completely true.
One could run python under wine and get -- at least a part of -- the 
Windows API.


>Square peg, round hole.

wine might be the tool that makes the square peg round.



Best regards,

Günther
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyVISA

2011-04-01 Thread Günther Dietrich
Manatee  wrote:

>I have unpacked the PyVISA files into the Python/lib/site-packages dir
>and from the IDLE GUI I get and error
>
>import visa
>
>Traceback (most recent call last):
>  File "", line 1, in 
>import visa
>ImportError: No module named visa
>
>
>
>There must be more to just putting the files in the correct directory.

Yes, there is more:

- DON'T unpack the files into any site-packages folder. If you already
  have done it, remove them.
- Unpack the PyVISA archive to any other folder.
- On the command line, change into the PyVISA folder. There you should
  find - among others - the two files setup.py and setup.cfg (at least
  if you use PyVISA-1.3.tar.gz).
- Now, it depends on what variant of python you use and want to install
  PyVISA for and on the configuration of your PYTHONPATH rsp. sys.path
  and the folders they point to.
  You can simply try: 'sudo python ./setup install'
  If you are lucky, that's it. If not, you have to decide, where the
  installation script has to put the files to. For example, for my
  python 2.6, I chose
  '/Library/Frameworks/Python.framework/Versions/2.6/'. In this path,
  there is a folder 'lib/site-packages', which is pointed to by
  sys.path, and where .pth files are evaluated.
- Edit the file setup.cfg. Near the end, in section '[install]', you will
  find the line 'prefix=/usr'. Replace the '/usr' by your chosen path.
- Save the file and retry the install (see above).



Best regards,

  Günther
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Inserting class namespace into method scope

2010-11-20 Thread Günther Dietrich
Steven D'Aprano  wrote:

>I find myself having need of a class where the class scope is included in 
>the scope of methods in the class. A simple example from Python 3.1:
>
>x = "outside"
>
>class Magic:
>x = "inside"
>def method(self):
>return x
>
>
>I would like Magic().method() to return "inside" rather than "outside".

Try this instead:
return self.x



Best regards,

Günther
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Light-weight/very-simple version control under Windows using Python?

2010-07-25 Thread Günther Dietrich
pyt...@bdurham.com wrote:

>I have some very simple use cases[1] for adding some version control
>capabilities to a product I'm working on. My product uses simple, text
>(UTF-8) based scripts that are independent of one another. I would like
>to "version control" these scripts on behalf of my users. By version
>control, I mean *very-simple* version control with no branching or
>merging - just the ability to store, list and restore a specific version
>of a file. The data store should be a local file with the ability to
>upsize to a multi-user database in the future.
>
>I'm looking for recommendations on possible solutions:
>
>1. Use an existing version control utility. There are lots of options
>here(!), any recommendations on a light weight, open source one that
>xcopy installs under Windows with lots of command line options?
>
>2. Interface to a hosted version control system (SaaS) that provides a
>RESTful API. Any recommendations here?
>
>3. Build this capability myself using Python and Python's DBI layer to
>store files in a local SQLite database at first (but with the ability to
>upsize to a real client server database in the future). Seems like a fun
>project to work on, but also smells like I'd be re-inventing the wheel
>with very little value added other than simpler deployment?
>
>Any suggestions appreciated.

Use Mercurial (). It is written in python, 
can be extended by python modules/packages and can be used by python 
programs directly.


>1. Check a file in with optional comment and username; ideally
>get a version number that can be used to reference this specific
>check-in in the future.

That's a basic task in mercurial (as probably in every version control 
system).


>2. Get a history listing of all checkins for a specific file
>(version number, timestamp, file size, user, comment)

Also avalilable. I am not sure about file size and comment, but if you 
have the list of version numbers, you can extract this info from the 
repository easily.


>3. Check out a specific version of a file by version number.

See point 1.


>4. Delete checked-in versions by version number, date range,
>and/or username.

I've never tried it with mercurial. There are a remove and a forget 
command. Maybe, one could use the rebase extension.

But deleting changesets from a repository usually is a bad idea.


>5. (Optional) Diff 2 versions of a file by version number and
>return diff in richly formatted format that visually shows
>changes via color and font effects (strikethru) (I'm thinking
>of using BeyondCompare for this if not present in a simple
>version control tool)

Also available.



Regards,

Günther
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Naming Conventions, Where's the Convention Waldo?

2010-07-11 Thread Günther Dietrich
rantingrick  wrote:

>Another source of asininity seems to be the naming conventions of the
>Python language proper! True/False start with an upper case and i
>applaud this. However str, list, tuple, int, float --need i go
>on...?-- start with lowercase.
>
>Q: Well what the hell is your problem Rick. Who cares right?
>
>WRONG, I tell you what my problem is. Now i cannot "wisely" use
>variables like...
>
>str="this is a string"
>list = [1,2,3]
>def make_random_objs(range=10)
>def show_message(str)
>int = 12

Someone who wants to write readable and maintainable code would 
(practically) never want to use variables named in this way. Why? 
Because these names don't tell anything about the purpose of the 
variables.
So, it is not a disadvantage that the functions you listed above are 
named in this way. In the contrary, it is an advantage, as it keeps 
newcomers from using stupid variable names.


>If we would have adopted proper naming conventions from dios numero
>uno all this nonsense would be rectified! Str, Float, List, Range,
>etc, etc. You think Python 3000 was a hump to climb over just wait for
>Python 4000.

Additionally to what I mention above, there is PEP 0008. Read it, you 
can learn from it. What you listed above, are functions, and their names 
comply completely with PEP 0008.



Regards, 

Günther




PS: Even though I suspect that you are simply an agitator rsp. troll 
(based on what you posted in this group so far), and normally I refuse 
to feed trolls, I make an exception in this case, so newcomers ar not 
mislead by your half-baked ideas.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: changing format of time duration.

2010-06-04 Thread Günther Dietrich
Gabriel Genellina  wrote:

>Try the strptime method with a suitable format, like this (untested):
>delta = now2-now1
>delta.strftime('%H:%M:%S.%f')

Throws an exception:

|Traceback (most recent call last):
|  File "", line 1, in 
|AttributeError: 'datetime.timedelta' object has no attribute 'strftime'

What seems logical, since the documentation doesn't mention an strftime 
method for timedelta.



Regards,

Günther
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Kindly show me a better way to do it

2010-05-08 Thread Günther Dietrich
Tycho Andersen  wrote:

>On Sat, May 8, 2010 at 3:41 PM, Oltmans  wrote:
>> Hi, I've a list that looks like following
>>
>> a = [ [1,2,3,4], [5,6,7,8] ]
>>
>> Currently, I'm iterating through it like
>>
>> for i in [k for k in a]:
>>        for a in i:
>>                print a
>>
>> but I was wondering if there is a shorter, more elegant way to do it?
>
>How about itertools? In python 2.6:
>
 a = [ [1,2,3,4], [5,6,7,8] ]
 from itertools import chain
 for i in chain(*a):
>... print i
>...
>1
>2
>3
>4
>5
>6
>7
>8


Why not this way?

>>> a = [[1,2,3,4], [5,6,7,8]]
>>> for i in a:
... for j in i:
... print(j)
... 
1
2
3
4
5
6
7
8

Too simple?



Best regards,

Günther
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: formatting a number as percentage

2010-02-23 Thread Günther Dietrich
Hans Mulder  wrote:

>> Did you try this:
>> 
> print('%d%%' % (0.7 * 100))
>> 70%
>
>That method will always round down; TomF's method will round to
>the nearest whole number:
>
> >>> print "%d%%" % (0.698 * 100)
>69%
> >>> print "{0:.0%}".format(.698)
>70%

It was intended as a hint to this way of formatting. He could also try:

>>> print('%.0f%%' % (0.698 * 100))
70%



Best regards,

Günther
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: formatting a number as percentage

2010-02-21 Thread Günther Dietrich
vsoler  wrote:

>I'm trying to print .7 as 70%
>I've tried:
>
>print format(.7,'%%')
>.7.format('%%')
>
>but neither works. I don't know what the syntax is...

Did you try this:

>>> print('%d%%' % (0.7 * 100))
70%



Best regards,

Günther
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: create a string of variable lenght

2010-01-31 Thread Günther Dietrich
Tracubik  wrote:

>i want to print on linux console (terminal) a message like this one:
>
>
>error message of variable lenght
>
>
>to print the asterisks line i do this:
>
>def StringOfAsterisks(myString):
>asterisksString = "*"
>for i in range(1,len(myString):
>   asterisksString += "*"
>print asterisksString

def StringOfAsterisks(myString):
print(''.ljust(len(myString), '*'))

You might use string methods .rjust() or .center() instead of method 
.ljust().


>the code seem to work for me, but it doesn't work properly if in errorMsg 
>there is some "esotic" char like euro char (€):
>
 euro = "€"
 len(euro)
>3

Maybe you might solve this if you decode your string to unicode.
Example:

|>>> euro = "€"
|>>> len(euro)
|3
|>>> u_euro = euro.decode('utf_8')
|>>> len(u_euro)
|1

Adapt the encoding ('utf_8' in my example) to whatever you use.

Or create the unicode string directly:

|>>> u_euro = u'€'
|>>> len(u_euro)
|1



Best regards,

Günther
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Default path for files

2010-01-24 Thread Günther Dietrich
Rotwang  wrote:

>> Check out http://docs.python.org/library/os.html and the function
>> chdir it is what you are looking for.
>
>Thank you. So would adding
>
>import os
>os.chdir()
>
>to site.py (or any other module which is automatically imported during 
>initialisation) change the default location to  every time I used 
>Python?

Don't change the library modules. It would catch you anytime when you 
expect it least.

See for the environment variable PYTHONSTARTUP and the associated 
startup file.



Best regards,

Günther
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python IDE for MacOS-X

2010-01-19 Thread Günther Dietrich
Jean Guillaume Pyraksos  wrote:

>What's the best one to use with beginners ?
>Something with integrated syntax editor, browser of doc...
>Thanks,

I started with 'EasyEclipse for Python', but soon changed to Eclipse 
with PyDev, MercurialEclipse and AnyEditTools plugins installed manually.

I can recommend the combination Eclipse/PyDev.



Best regards,

Günther
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: NumPy installation won't import correctly

2009-12-01 Thread Günther Dietrich
Ethos  wrote:

>I installed NumPy for python 2.6 on my leopard macbook, using the
>nifty mac installer they now provide. I have the 2.6 official python
>distro installed on my computer, in addition to the 2.5 that is native
>on the mac. When I went to test out the installation, with 2.6, it
>gave me this:
>
 import numpy
>Traceback (most recent call last):
>  File "", line 1, in 
>  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
>python2.6/site-packages/numpy/__init__.py", line 132, in 
>import add_newdocs
>  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
>python2.6/site-packages/numpy/add_newdocs.py", line 9, in 
>from lib import add_newdoc
>  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
>python2.6/site-packages/numpy/lib/__init__.py", line 4, in 
>from type_check import *
>  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
>python2.6/site-packages/numpy/lib/type_check.py", line 8, in 
>import numpy.core.numeric as _nx
>  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
>python2.6/site-packages/numpy/core/__init__.py", line 5, in 
>import multiarray
>ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.6/
>lib/python2.6/site-packages/numpy/core/multiarray.so, 2): no suitable
>image found.  Did find:
>   /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-
>packages/numpy/core/multiarray.so: unknown required load command
>0x8022

I had the same problem when I tried to use the MacPorts installation of 
python3 within blender2.5alpha0 (I pointed the PYTHONPATH to the 
respective MacPorts python3 folder). I figured out, that the blender 
binary is a 64bit one, but the libraries of the MacPorts python3 are 
32bit ones and these two don't fit together.

Then I found out, that -- as opposed to blender 2.4x -- blender 2.5 
comes with all the standard python library bundled. So I'm fine with the 
pure blender 2.5 for the testing.



Best regards,

Günther
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IDE+hg

2009-11-30 Thread Günther Dietrich
In article ,
 "Günther Dietrich"  wrote:

>>Since no py IDE I found has easy hg access.
>
>Obviously, you didn't try Eclipse with PyDev (<http://www.pydev.org>) 
>and Mercurial Eclipse (<http://www.vectrace.com/mercurialeclipse/>) 
>plugins.
>This combination is also available stuffed into one package as 
>'EasyEclipse for Python' (<http://www.easyeclipse.org>).

Correction: EasyEclipse for Python does not contain the Mercurial 
Eclipse plugin. That has to be installed by hand in both cases.



Sorry,

Günther
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IDE+hg

2009-11-24 Thread Günther Dietrich
NiklasRTZ  wrote:

>Since no py IDE I found has easy hg access.

Obviously, you didn't try Eclipse with PyDev () 
and Mercurial Eclipse () 
plugins.
This combination is also available stuffed into one package as 
'EasyEclipse for Python' ().

Both, pure Eclipse with plugins installed by hand, and EasyEclipse, are 
very convenient for python development.



Best regards,

Günther
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Formatted input function

2009-09-05 Thread Günther Dietrich
candide  wrote:

>In C, we would manage this with the following statement :
>
>fscanf(foo_file, "Best score : %d", &score);
>
>Does Python provide an equivalent ?

RTFM!  :)

In the python 2.5 manual: Chapter 4.2.6 (search pattern 'scanf' on the 
index tab of python25.chm)

There are some scanf-patterns with corresponding regular expressions 
listed.

Works quite nice.



Best regards,

Günther
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is behavior of += intentional for int?

2009-08-29 Thread Günther Dietrich
Paul McGuire  wrote:

>What exactly are you trying to do?

I think, he wants to kind of dereference the list element. So that he 
can write

>>> a += 1

instead of

>>> long_name_of_a_list_which_contains_data[mnemonic_pointer_name] += 1



Regards,

Günther
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is behavior of += intentional for int?

2009-08-29 Thread Günther Dietrich
zaur  wrote:

>Python 2.6.2 (r262:71600, Apr 16 2009, 09:17:39)
>[GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin
>Type "copyright", "credits" or "license()" for more information.
 a=1
 x=[a]
 id(a)==id(x[0])
>True
 a+=1
 a
>2
 x[0]
>1
>
>I thought that += should only change the value of the int object. But
>+= create new.
>Is this intentional?

An integer variable contains the reference (ID) to an (immutable) 
integer object; it doesn't contain the value itself. So, when you assign 
a new value to an integer variable, it will contain the reference to the 
object containing the new value, afterwards.

If you assign an integer variable to a list element, this reference will 
be written into the list. The assignment of a new value to the integer 
variable will create a new integer object, containing the new value, and 
put the reference to it into the integer variable.
The reference to the object with the old value, that is stored in the 
list, won't be touched.


In fact, it is a result of integers in python being immutable.



Best regards,

Günther
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What text editor is everyone using for Python

2009-05-25 Thread Günther Dietrich
LittleGrasshopper  wrote:

>With so many choices, I was wondering what editor is the one you
>prefer when coding Python, and why.

[...]

>So what do you guys use, and why? Hopefully we can keep this civil.

I found 'EasyEclipse for Python' soon after I began using Python. With 
PyDev, it even contains a Python debugger.
After adding a Mercurial plug-in, it has all I need for Python 
programming.
One disadvantage of EasyEclipse is, that they mangled the install/update 
system, so that it is very difficult to find the original Eclipse 
plug-ins/features.

So, in between, I replaced EasyEclipse by Eclipse, with all the plug-ins 
that came bundled with 'EasyEclipse for Python' installed by hand, but 
more actual versions.
In my opinion, it is a very convenient system for Python development, 
especially due to the debugger.
If you don't use the free PyDev, but the commercial one, you even get a 
debugger for remote debugging. Useful e.g. for debugging of blender 
scripts.



Best regards,

Günther
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Convert variable directly into a string (no ASCII)

2009-05-02 Thread Günther Dietrich
Justin Rajewski  wrote:

>I need to print variables out over serial, however I need them to not be
>in ASCII, ie if the variable is 5 then print 5 not "5".
>
>The function that writes to the serial port requires a string and I can
>send non-variables out with the string "/x05" for 5.

See module struct:

>>> struct.pack('b', 5)
'\x05'
>>> struct.pack('', 5, 150, 3, 224)
'\x05\x96\x03\xe0'



Regards,

Günther
--
http://mail.python.org/mailman/listinfo/python-list


Re: problem with money datatype based calculations in python

2009-05-02 Thread Günther Dietrich
Krishnakant  wrote:

['money datatype' for database stored values]

What ist the real problem? Do you have problems converting results of 
float calculations to the 'money datatype' before storing them in the 
database, or do you want to avoid the precision issues which come with 
the conversion od non-integer values between binary and decimal?
In the latter case use the Decimal data type from module decimal (comes 
with the python distribution -- it is mentioned in the tutorial).



Regards,

Günther
--
http://mail.python.org/mailman/listinfo/python-list


Re: ctypes: reference of a struct member?

2009-05-01 Thread Günther Dietrich
ma  wrote:

>If I have this struct in C:
>
>struct spam {
> int ham;
>  char foo;
>};
>
>
>if I have this declaration:
>struct spam s_;
>
>If I wanted to pass a reference to a function of s_'s foo character, I
>can do something like this:
>
>somefunc(&s_.foo)
>
>How do I do the same thing in ctypes?
>ctypes.addressof(s_) + ctypes.sizeof(spam.foo)*(1)

See ctypes.create_string_buffer().
To unpack the struct elements received from the C function, use 
struct.unpack().

Here some example:

def rssiam_volt_Q(self):
'''Output Voltage Query
'''
query_buffer = ctypes.create_string_buffer(8)
self.rssiam_32_dll.rssiam_volt_Q.argtypes = [ctypes.c_long,
 ctypes.c_char_p]
result = self.rssiam_32_dll.rssiam_volt_Q(self.session,
  query_buffer)
if result != VI_SUCCESS:
raise IOError, 'rssiam_volt_Q: result = %d' % result
return(struct.unpack('d', query_buffer.raw)[0])


In this case, it is a 64 bits float (= double) value that is returned by 
reference (query_buffer).
Attention, struct.unpack() returns a tuple, even when there is only a 
single element to extract from the buffer.




Regards,

Günther
--
http://mail.python.org/mailman/listinfo/python-list


Re: Please help with problem creating class

2009-04-18 Thread Günther Dietrich
auzarski2...@gmail.com wrote:

>I am using tab separated data in another file that looks like this...
>
>
>appname1   leadername12005, 02, 022006, 02, 02
>appname2   leadername22006, 03, 212007, 06, 28
>
>etc...
>
>The error message looks like this
>
> back (most recent call last):
>  File "/home/amy/Documents/LIS452/assignment 3/testworks.py", line
>97, in 
>main()
>  File "/home/amy/Documents/LIS452/assignment 3/testworks.py", line
>80, in main
>a = Leaderapplicant(line) #from data file
>  File "/home/amy/Documents/LIS452/assignment 3/testworks.py", line 9,
>in __init__
>appname, leadername, start, end = line.split("\t")
>ValueError: need more than 3 values to unpack

You assign the result of line.split() to four variables. So split needs 
at least four fields (that's more than three) in line to process.

Examine your input data ("appname1   leadername1   2005..."), if it 
_really_ contains alt least three tab characters to separate the data 
fields.
Maybe you created the input file by means of the same editor you use for 
coding your python code, so the probability is high, that the editor 
produces multiple space characters when you press the tab key.
You could load the input file into vi or vim and give vi/vim the command

:set list

In list mode, tabs are rendered as '^I' (without the quotes).

Or you use a hex editor or something like od to inspect the input file.



Best regards,

Günther
--
http://mail.python.org/mailman/listinfo/python-list