Re: [Tutor] argparse iterable

2013-04-02 Thread Dave Angel

On 04/01/2013 10:34 PM, Mark Lawrence wrote:

On 02/04/2013 02:37, Dave Angel wrote:

On 04/01/2013 09:31 PM, Mark Lawrence wrote:


for a in vars(parser.parse_args()):
 print('This arg is %s' % a)

http://docs.python.org/3/library/argparse.html#the-namespace-object

Please don't ask me for an explanation as it took me long enough to work
this out from the docs :)



http://docs.python.org/2/library/argparse.html

 see section 15.4.4.6 for a very brief explanation of vars()




Section 15.4.4.6. The Namespace object, but I can't for the life of me
remember what my link referred to :)



Whoops, sorry.  I didn't notice your link was equivalent to (better 
than) mine.  I had worked it out before your message showed up, then 
abandoned all of my message except for the link.


BTW, can you tell me how you get the #the-namespace-object part of your 
link?  Is there some technique (without actually looking in the source 
code for the page) for finding the nearest id= ?  I've now figured out 
how to do it for pages like this one with a TOC, but is there a more 
general way?


For others like me:
If there's a TOC (table of contents) for a page, you can right-click on 
the link to the particular section of the page, and COPY it to the 
clipboard.  It'll then have the form like:

  http://docs.python.org/3/library/argparse.html#the-namespace-object

where the last field specifies the particular section of the page desired.



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


Re: [Tutor] argparse iterable

2013-04-02 Thread Dave Angel

On 04/01/2013 10:28 PM, ke...@kendy.org wrote:

You guys are awesome! You make it look easy and I learn every time.



Once you've got the two dicts, take a look into the update method.  It 
may make any loops unnecessary, except for debugging.



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


Re: [Tutor] tadaahh! But how to identify zLinux?

2013-04-02 Thread Albert-Jan Roskam
> Subject: Re: [Tutor] tadaahh! But how to identify zLinux?
> 
> On 02/04/13 09:00, Alan Gauld wrote:
>> On 01/04/13 21:04, Albert-Jan Roskam wrote:
>> 
>>> program is supposed to work with zLinux (IBM system Z). But how do I
>>> know that this system is used?
>> 
>> I have no idea what the answer is but I'm curious why you would care?
>> Are you expecting that your code will be run on an IBM mainframe?
> 
> Perhaps he is :-)

Umm, well it'd be cool. And it's also kind of to satisfy my intellectual 
hunger/curiosity. I had never heard of zLinux before, but now I've read a thing 
or two about it.
 
> Albert-Jan asks because his package is an interface to an external binary
> library, and the location of that library differs according to the platform:

 
Yes, exactly right. It's cool if it just works for all supported platforms.
 
>https://bitbucket.org/fomcl/savreaderwriter/src/09b9c82406e82d43223d6610ba9cbfbf234b16d4/savReaderWriter/generic.py?at=master
> 
> By the way, I don't know that changing directory is a good idea, if you can
> avoid it at all. I for one would be *extremely* annoyed if, after calling
> what otherwise seems like an innocent library routine, opening files suddenly
> started failing (or worse, the wrong file was opened!) because the current
> directory was different. Even though you do restore the current directory
> when you are done, that makes your routines unsafe for threads.

 
That loadLibrary method has been kind of a challenge. The chdir may very well 
be only needed on Windows. I'd have to test this (in sofar as I've access to 
any of these platforms). I like the fact that, under Windows, things work out 
of the box, without needing to modify PATH.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] tadaahh! But how to identify zLinux?

2013-04-02 Thread Albert-Jan Roskam
> From: eryksun 
> To: Albert-Jan Roskam 
> Cc: tutor@python.org
> Sent: Tuesday, April 2, 2013 4:57 AM
> Subject: Re: [Tutor] tadaahh! But how to identify zLinux?
> 
> On Mon, Apr 1, 2013 at 6:42 PM, Steven D'Aprano  
> wrote:
>> By the way, I don't know that changing directory is a good idea, if you 
> can
>> avoid it at all.
> 
> As far as loading linked libraries goes, changing the current
> directory works on Windows, and I think OS X, but it doesn't work on
> Linux. On Windows you can also add the directory to the system PATH at
> run time.

Ok, I'll improve that method and ditch the os.chdir calls.

> I see 3 deb files in spssio/lin32. It doesn't seem like your plan is
> to install these since you don't have them for lin64 as well. Is this
> savReaderWriter supposed to be a self-contained system for
> reading/writing IBM SPSS files, or dependent on an existing
> installation of SPSS? (Not being a user of SPSS, I have no idea how
> foolish that question may or may not sound. Oh well.)

Yes, savReaderWriter is supposed to be a self-contained system, without the 
need for an expensive license.
I put the 3 .deb files there as a convenience. I run Linux on a 32-bit system, 
so I thought I 'd just also include those files.
In the help I mentioned these specific dependencies: 
http://pythonhosted.org/savReaderWriter/

> Anyway, I downloaded and extracted the deb files to a temp directory
> on a 32-bit Debian system. In addition to the libs that you've already
> extracted, ldd determined that I also needed the following libs:
> 
> libimf.so          [intel-icc8-libs_8.0-1_i386.deb]
> libcxaguard.so.5  [intel-icc8-libs_8.0-1_i386.deb
> libstdc++.so.5.0.7 [libstdc++5_3.3.6-20_i386.deb]
> 
> and links for the ELF soname fields:
> 
> libstdc++.so.5    ->  libstdc++.so.5.0.7
> libicudata.so.32  ->  libicudata.so.32.0
> libicui18n.so.32  ->  libicui18n.so.32.0
> libicuuc.so.32    ->  libicuuc.so.32.0

How exactly did you do this?

> After setting up the above, I patched a runpath of $ORIGIN into
> libspssdio.so.1. This instructs the loader to look for dependencies in
> the same directory.
> 
>     $ patchelf --set-rpath '$ORIGIN' libspssdio.so.1
> 
> Now I can load the library with ctypes:
> 
>     >>> from ctypes import *
>     >>> spssio = CDLL('spssio/lin32/libspssdio.so.1')
>     >>> spssio.spssOpenRead
>     <_FuncPtr object at 0xb753b094>

Awesome. I knew about patchelf but I didn't feel confident enough to use this 
(I believe I fainted when I did 'man ld' ;-). Moreover, as we discussed before, 
I wasn't sure whether patching the ELF header would somehow be in violation of 
the IBM license agreement. I guess that including as shell script with the 
savReaderWriter package with the patchelf code would be okay.

I'll look into this in more detail when I'm on a Linux box again. I might be 
back with more questions. ;-) 

May I ask if you run Linux 64 bit? I haven't been able to try the program on 
Linux 64 (only win32, win64, lin32, mac and, shortly, also aix64). I would be 
really pleased to know if this also works on Linux 64 (zLinux will remain a 
surprise, for now ;-). This code should run without errors:

import tempfile, os
from savReaderWriter import *

 
savFileName = os.path.join(tempfile.gettempdir(), "someFile.sav")
records = [['Test1', 1, 1], ['Test2', 2, 1]] 
varNames = ['var1', 'v2', 'v3'] 
varTypes = {'var1': 5, 'v2': 0, 'v3': 0} 
with SavWriter(savFileName, varNames, varTypes) as writer: 
    for record in records: 
    writer.writerow(record) 

with SavReader(savFileName, returnHeader=True) as reader: 
 header = reader.next()
 print header
 for record in reader:
 print record 

Tutors, thanks again!
 
Albert-Jan
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] argparse iterable

2013-04-02 Thread eryksun
On Tue, Apr 2, 2013 at 5:48 AM, Dave Angel  wrote:
>
> BTW, can you tell me how you get the #the-namespace-object part of your
> link?  Is there some technique (without actually looking in the source code
> for the page) for finding the nearest id= ?


16.4.4.6. The Namespace object
  
  ¶
  


The paragraph symbol (¶) appears when you hover over the heading.
Click it to get the anchor. Here's the bit of CSS that makes the
headerlink visible when you hover:

a.headerlink {
visibility: hidden;
}
h1:hover > a.headerlink,
h2:hover > a.headerlink,
h3:hover > a.headerlink,
h4:hover > a.headerlink,
h5:hover > a.headerlink,
h6:hover > a.headerlink,
dt:hover > a.headerlink {
visibility: visible;
}

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


Re: [Tutor] argparse iterable

2013-04-02 Thread Mark Lawrence

On 02/04/2013 10:48, Dave Angel wrote:


BTW, can you tell me how you get the #the-namespace-object part of your
link?  Is there some technique (without actually looking in the source
code for the page) for finding the nearest id= ?  I've now figured out
how to do it for pages like this one with a TOC, but is there a more
general way?


I'm not aware of one, which obviously doesn't mean there's no such beast.



For others like me:
If there's a TOC (table of contents) for a page, you can right-click on
the link to the particular section of the page, and COPY it to the
clipboard.  It'll then have the form like:
   http://docs.python.org/3/library/argparse.html#the-namespace-object

where the last field specifies the particular section of the page desired.



I also go for the cut and paste approach.  Maybe we need Bicycle Repair 
Man to do some searching for us? :)


--
If you're using GoogleCrap™ please read this 
http://wiki.python.org/moin/GoogleGroupsPython.


Mark Lawrence

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


[Tutor] Python help!!

2013-04-02 Thread David Mitchell
Hi!
How do I go through a text file, finding specific words/numbers/phrases and 
edit them to say different things? I do not want to edit the text file, I would 
rather open and read from the text file and write to a new file. 
I do NOT want to know how to replace a specific word with another every time it 
appears. There are some "OFF" 's that i would like to change to "ON" 's and 
some that I would like to change to "OPEN" for example. 
I am doing all this in Linux Fedora with gedit. It is a project assigned to me 
from my boss and I'm just a co-op student so I could really use the help. 
Any help would be greatly appreciated!!
Thanks,
David ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python help!!

2013-04-02 Thread taserian
On Tue, Apr 2, 2013 at 12:49 PM, David Mitchell wrote:

> Hi!
>
> How do I go through a text file, finding specific words/numbers/phrases
> and edit them to say different things? I do not want to edit the text file,
> I would rather open and read from the text file and write to a new file.
>
> I do NOT want to know how to replace a specific word with another every
> time it appears. There are some "OFF" 's that i would like to change to
> "ON" 's and some that I would like to change to "OPEN" for example.
>

How would you know which ones to change to "ON" and which ones to change to
"OPEN"? Additionally, how would you describe those conditions in Python?


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


Re: [Tutor] Python help!!

2013-04-02 Thread Bod Soutar
On 2 April 2013 17:49, David Mitchell  wrote:
> Hi!
>
> How do I go through a text file, finding specific words/numbers/phrases and
> edit them to say different things? I do not want to edit the text file, I
> would rather open and read from the text file and write to a new file.
>
> I do NOT want to know how to replace a specific word with another every time
> it appears. There are some "OFF" 's that i would like to change to "ON" 's
> and some that I would like to change to "OPEN" for example.
>
> I am doing all this in Linux Fedora with gedit. It is a project assigned to
> me from my boss and I'm just a co-op student so I could really use the help.
>
> Any help would be greatly appreciated!!
>
> Thanks,
>
> David

Can you give us some idea of your skill level, and perhaps some code
that you've already tried?
Your general approach will be something like

open read_file
open write_file
read read_file into a list
close read_file
iterate over the list
if you find a line you want to change
make the change and write to write_file
else
write to write_file

close write_file

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


Re: [Tutor] Python help!!

2013-04-02 Thread Elegbede Muhammed Oladipupo

What exactly do you know how to do?

Can you read files?
Can you replace words?

This way, I can know how to help. 
What is hard for me to help with is the fact that you are planning to replace 
the same word with two different words depending on location e.g when you said 
you want to change off to either on or open. 

Let's see what you can do or have done, then help should be on the way. 

Regards. Regards. 
Sent from my BlackBerry®  PORSCHE® DESIGN wireless handheld from Glo Mobile.

-Original Message-
From: David Mitchell 
Sender: "Tutor" Date: 
Tue, 2 Apr 2013 12:49:32 
To: tutor@python.org
Subject: [Tutor] Python help!!

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

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


Re: [Tutor] Python help!!

2013-04-02 Thread Alan Gauld

On 02/04/13 17:49, David Mitchell wrote:


How do I go through a text file, finding specific words/numbers/phrases
and edit them to say different things? I do not want to edit the text
file, I would rather open and read from the text file and write to a new
file.


OK That's easy, you just write the old file to the new file with the 
changes in place.



I do NOT want to know how to replace a specific word with another every
time it appears. There are some "OFF" 's that i would like to change to
"ON" 's and some that I would like to change to "OPEN" for example.


OK so, instead of calling replace, you want to stop and ask the user for 
a replacement text? Is that the idea?



I am doing all this in Linux Fedora with gedit.


I don't know gedit but both vim and emacs have interactive
replacement functions, maybe gedit has too. Both vi and
emacs can create macros and you can auto run macros when
you start the editor, so you could automate it all
using those tools.

But Python can work almost as easily (and probably the
finished article will be faster)


Any help would be greatly appreciated!!


Why don't you tell us how you think it should work?
Its likely that all the bits you need are already
available to you with a little thought. Research
the string methods (and if you want to get (too) clever
the re module too).

(I'm assuming these files are short enough to read them
all into memory as a single string? If not we need to
get slightly smarter.)

Try a solution and tell us where you get stuck.
Even pseudo code if you aren't confident with
real Python.

If that's too hard at least try to produce a hypothetical
user session showing us what you expect the program
to look like in use.

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

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


[Tutor] Need help on win32 application error

2013-04-02 Thread Ankesh.Pratap
Hi Team,
I am facing folowing erro while executing python code:
Win32 exception occurred releasing IUnknown at 0x03210eb8
Please let me know the resolution of the same.PFA the version details of python 
exe that I am using.


Thanks and Regards,
 Ankesh Pratap

Programmer Analyst
Mobile: 91-9884928733
This e-mail and any files transmitted with it are for the sole use of the 
intended recipient(s) and may contain confidential and privileged information. 
If you are not the intended recipient(s), please reply to the sender and 
destroy all copies of the original message. Any unauthorized review, use, 
disclosure, dissemination, forwarding, printing or copying of this email, 
and/or any action taken in reliance on the contents of this e-mail is strictly 
prohibited and may be unlawful.
<>___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Need help on win32 application error

2013-04-02 Thread Bod Soutar
On 2 April 2013 19:19,   wrote:
> Hi Team,
> I am facing folowing erro while executing python code:
> Win32 exception occurred releasing IUnknown at 0x03210eb8
> Please let me know the resolution of the same.PFA the version details of 
> python exe that I am using.
>
>
> Thanks and Regards,
>  Ankesh Pratap
>
> Programmer Analyst
> Mobile: 91-9884928733
> This e-mail and any files transmitted with it are for the sole use of the 
> intended recipient(s) and may contain confidential and privileged 
> information. If you are not the intended recipient(s), please reply to the 
> sender and destroy all copies of the original message. Any unauthorized 
> review, use, disclosure, dissemination, forwarding, printing or copying of 
> this email, and/or any action taken in reliance on the contents of this 
> e-mail is strictly prohibited and may be unlawful.
>
I'd say the Win32 module threw an exception when trying to release
something at the memory address 0x03210eb8..
But that's just a rough guess you understand.

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


Re: [Tutor] tadaahh! But how to identify zLinux?

2013-04-02 Thread eryksun
On Tue, Apr 2, 2013 at 7:19 AM, Albert-Jan Roskam  wrote:
>> On Windows you can also add the directory to the system PATH at
>> run time.
>
> Ok, I'll improve that method and ditch the os.chdir calls.

Win32 LoadLibrary searches system directories, the executable's
directory, the current directory, and finally PATH. It's simple to
update the PATH environment variable for the current process:

os.environ['PATH'] = ';'.join([absolute_lib_path, os.environ['PATH']])

You can also call kernel32.SetDllDirectoryW(absolute_lib_path) to
insert a path to be searched immediately after the executable's
directory. Afterward call kernel32.SetDllDirectoryW(None) to restore
the normal safe search order.

>> Anyway, I downloaded and extracted the deb files
>> 
>> and links for the ELF soname fields
>
> How exactly did you do this?

I extracted the debs:

dpkg-deb -x  

Then I copied the required .so files to the lin32 directory and
created the symbolic links with "ln".

> Moreover, as we discussed before, I wasn't sure whether patching
> the ELF header would somehow be in violation of the IBM license
> agreement. I guess that including as shell script with the
> savReaderWriter package with the patchelf code would be okay.

The Debian repo has ICU 4.8 (libicu48). It also has libstdc++5. I'm
sure the same applies to other Linux distros. That leaves only Intel's
C++ libraries to be installed: libimf.so, libirc.so, and
libcxaguard.so.5. I think Intel's license allows you to redistribute
these with an application. Anything less would be unreasonable. But...

Actually, the fact the lin32 and lin64 versions in your repo were
linked to different versions of ICU made me suspicious. I decided to
downloaded "IO_Module_for_SPSS_Statistics_21001.zip" (version 21) to
get the lin32 directory from the source. Turns out this version
doesn't depend on Intel's libs at all, and it's linked to the ICU 4.8
libs and libstdc++.so.6. It does add libzlib123spss.so, but that's
simple to preload.

In fact, if you'd rather not tinker with PATH on Windows, or install
libraries to the system, or patch the ELF runpath -- then you could
simply load the required libraries manually in the following sequence
(version 21):

Linux Windows
-
libicudata.so.48.1icudt48.dll
libicuuc.so.48.1  icuuc48.dll
libicui18n.so.48.1icuin48.dll
libzlib123spss.so zlib123spss.dll
libspssdio.so.1   spssio32.dll [spssio64.dll]
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] argparse iterable

2013-04-02 Thread kendy
I forgot about update. It's nice and clean:

 a.update(b)

However, when 'a' has values and 'b' is None, the 'a' item gets clobbered with
None. I found this on stackoverflow.com:

--
old = {1: 'one', 2: 'two'}
new = {1: 'newone', 2: None, 3: 'new'}
old.update( (k,v) for k,v in new.iteritems() if v is not None)
--

Exactly what I need.

Thanks for the update hint!
Ken

On Tue Apr  2  2:50 , Dave Angel  sent:

>On 04/01/2013 10:28 PM, ke...@kendy.org wrote:
>> You guys are awesome! You make it look easy and I learn every time.
>>
>
>Once you've got the two dicts, take a look into the update method.  It 
>may make any loops unnecessary, except for debugging.
>
>
>-- 
>DaveA
>___
>Tutor maillist  -  Tutor@python.org
>To unsubscribe or change subscription options:
>http://mail.python.org/mailman/listinfo/tutor


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


Re: [Tutor] Need help on win32 application error

2013-04-02 Thread Alan Gauld

On 02/04/13 19:19, ankesh.pra...@cognizant.com wrote:

Hi Team,
 I am facing folowing erro while executing python code:
 Win32 exception occurred releasing IUnknown at 0x03210eb8
Please let me know the resolution of the same.PFA the version details of python 
exe that I am using.


The solution is that you need to fix an error in your code.

But without any clue as to what your code looks like how are we supposed 
to guess what caused the error?


I assume you don't get this just starting IDLE?

What code are you running?
How are you running it?
Do you get any other output - like a window displayed,
text in the shell window of IDLE? Anything?
Which version of windows are you using? From the screenshot
it looks like XP but that could just be a UI setting...

We need more detail.

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

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


Re: [Tutor] Need help on win32 application error

2013-04-02 Thread Tim Golden

On 02/04/2013 19:19, ankesh.pra...@cognizant.com wrote:

 I am facing folowing erro while executing python code:
 Win32 exception occurred releasing IUnknown at 0x03210eb8


You need to give us a bit more of a clue as to what your code does. My 
guess is that you're using the pywin32 packages and, possibly, the MAPI 
COM interface? That occasionally throws up that sort of exception. 
Assuming I'm right, you're better off asking on the python-win32 mailing 
list, ideally with a reproducible code sample.


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