Saturday, January 9, 2010

comp.lang.python - 25 new messages in 11 topics - digest

comp.lang.python
http://groups.google.com/group/comp.lang.python?hl=en

comp.lang.python@googlegroups.com

Today's topics:

* Microsoft Office Word and Python (Win XP) - 5 messages, 4 authors
http://groups.google.com/group/comp.lang.python/t/5aba5d0795b3ea0b?hl=en
* Something More Elegant - 2 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/d88f8630a9cdd805?hl=en
* Easy Q - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/978a788bdaac2954?hl=en
* interactive terminal in Ubuntu Linux : libreadline5-dev works only in Python
2.6 not 3.1 - 4 messages, 3 authors
http://groups.google.com/group/comp.lang.python/t/e78273d8ffda71ae?hl=en
* lightweight encryption of text file - 4 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/b31a5b5f58084f12?hl=en
* Scripting (was Re: Python books, literature etc) - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/6ad7a20513065f9f?hl=en
* PIL show() not working for 2nd pic - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/faa125f29fd5fe93?hl=en
* [RELEASED] Python 2.7 alpha 2 - 3 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/f1c68d96f3e86f41?hl=en
* Link to module Stack - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/5f7014f20243d059?hl=en
* Append to an Excel file - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/6e21b15ce9abeb32?hl=en
* Prepend to logging message - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/dda048a92c122117?hl=en

==============================================================================
TOPIC: Microsoft Office Word and Python (Win XP)
http://groups.google.com/group/comp.lang.python/t/5aba5d0795b3ea0b?hl=en
==============================================================================

== 1 of 5 ==
Date: Sat, Jan 9 2010 10:00 am
From: Terry Reedy


On 1/9/2010 10:12 AM, 3lvss0809@gmail.com wrote:

> I need the script that moves (only moves, not change or delete!)
> entire (100% of the text) text from one .doc file to another.

If you want to copy files without modification, use the OS copy command.
You can use the subprocess module to do that from Python.

== 2 of 5 ==
Date: Sat, Jan 9 2010 10:00 am
From: Dennis Lee Bieber


On Sat, 9 Jan 2010 07:12:18 -0800 (PST), "3lvss0809@gmail.com"
<3lvss0809@gmail.com> declaimed the following in
gmane.comp.python.general:

> Hi.
> Im very new with python. I have got some answer on my issue to use
> interop or COM ''plugins'' to access MS Word through python but i
> don't even know what those two ''plugins'' are so I cannot use them.
> What I want to do is the following:
>
For Word documents, you WILL have to use such (on Windows the win32
extension library gives you the needed interfaces -- though I've not
used them myself [figuring out how to do what you want using the VBA
built into Word is difficult enough, and that IS pretty much the COM
interface]). Possibly the ctypes module will also give you said
access...

>
> What I would like to have is moved the entire (but really all of the
> text, must be 100% all) text into the .doc file with the highest ( ! )
> number. The target .doc files will always start with ''HD'' and always
> be similar to above examples.
> It is possible that the doc file (target file) is only one, so only
> HD1.doc. Therefore ''1'' is the maximum number and the text is moved
> into this file.
> Sometimes the target file is empty but usually won't be. If it won't
> be then the text should be moved to the end of the text, into first
> new line (no empty lines inbetween).
> So for example in the target file which has the maximum number in its
> name is the following text:

<snip>
> Could someone tell me please how to do this?
>
How familiar with Python are you?

I'd prototype this using plain text files first, avoiding any usage
of COM/Word access -- just plain file and directory operations.

After you have verified all conditions (destination file exists,
moving to end of contents, reading source file, writing data to
destination -- note that whether the destination contains data or not is
not relevant, you are appending the source text to the /end/ of whatever
is in the destination) are functioning properly THEN study the Word COM
model and replace the file open/close/read/write operations with Word
COM operations to do the same thing. The directory operations to find
the destination file are not Word or COM related and won't change.

The Word COM model is not something you will find documents for in
Python (not even the win32 module docs cover specifics of individual
applications).
--
Wulfraed Dennis Lee Bieber KD6MOG
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/

== 3 of 5 ==
Date: Sat, Jan 9 2010 11:18 am
From: "3lvss0809@gmail.com" <3lvss0809@gmail.com>


Marco Nawijn: I have had installed pywin32 already. The three lines
that you mentoined don't do this, also what did you mean with "doc =
app.Documents.Open("c:\\example.doc")". Which document should I open
with this line? It shouldn't be opened anything. I was asking about
the script as automated process. If you know how could i do this?

Terry Reedy: I have never mentoined copying files but moving the whole
text from, always the same (same name, same path), .doc file with.
However copying (=moving) text to correct .doc file would be good yes.
I know command prompt and its copy function but this way it wouldn't
work because I would have to define the target file - the file INTO
which I want to move the text. But I will never know the file name
(target file). The only thing I know is:
- the file is one of .doc files that start with "HD"
- whole name of those .doc file is always HDX.doc where X is a number
and I need to move the text into the file with maximum X (the most
high number)
- all the HD files will be always in the same path (same folder) but I
would like to use the path inside the code (it might be obvious that I
have to) because on PC and laptop, I have two different usernames and
since HD files are located inside Documents And Settings, I have to
use two copies of the script - one for PC, one for laptop.

Dennis Lee Bieber: Im not familiar with python, also Im not
programmer. Thats why Im not able to do so when people tell me "do
this then use XYZ function which will give you ZYX from what you can
do that and you will get result". Im still willing to learn but there
are thousands of python tutorials and the one for exsactly this topic
probably doesn't exsist. The .doc extension is required, so I cannot
use .txt because I need the HD files in .doc.


== 4 of 5 ==
Date: Sat, Jan 9 2010 1:30 pm
From: Marco Nawijn


On Jan 9, 8:18 pm, "3lvss0...@gmail.com" <3lvss0...@gmail.com> wrote:
> Marco Nawijn: I have had installed pywin32 already. The three lines
> that you mentoined don't do this
I checked at my own computer and it works fine.
> also what did you mean with "doc =
> app.Documents.Open("c:\\example.doc")". Which document should I open
> with this line?
This was just meant as an example on how to open a Word document from
within python. This would be the basis for copying/appending from your
source
document to your target document (e.g. HD10.doc).
> It shouldn't be opened anything. I was asking about
> the script as automated process. If you know how could i do this?
Well it is a python script. So you can run it as an automated process.
You should just set app.Visible=False so the Word user interface
component
is not shown.

>
> Terry Reedy: I have never mentoined copying files but moving the whole
> text from, always the same (same name, same path), .doc file with.
> However copying (=moving) text to correct .doc file would be good yes.
> I know command prompt and its copy function but this way it wouldn't
> work because I would have to define the target file - the file INTO
> which I want to move the text. But I will never know the file name
> (target file). The only thing I know is:
> - the file is one of .doc files that start with "HD"
> - whole name of those .doc file is always HDX.doc where X is a number
> and I need to move the text into the file with maximum X (the most
> high number)
> - all the HD files will be always in the same path (same folder) but I
> would like to use the path inside the code (it might be obvious that I
> have to) because on PC and laptop, I have two different usernames and
> since HD files are located inside Documents And Settings, I have to
> use two copies of the script - one for PC, one for laptop.
>
> Dennis Lee Bieber: Im not familiar with python, also Im not
> programmer. Thats why Im not able to do so when people tell me "do
> this then use XYZ function which will give you ZYX from what you can
> do that and you will get result". Im still willing to learn but there
> are thousands of python tutorials and the one for exsactly this topic
> probably doesn't exsist. The .doc extension is required, so I cannot
> use .txt because I need the HD files in .doc.

== 5 of 5 ==
Date: Sat, Jan 9 2010 4:23 pm
From: "3lvss0809@gmail.com" <3lvss0809@gmail.com>


Marco did you also make the HD files to it worked for you? Because I
cannot even imagine how only three lines would do everything - find
correct folder (path) of the files, find maximum number, move the
entire text,... In this 3 lines is not stated that we are talking
about the files that start with "HD" so I wonder how it worked for
you. Nothing was moved on my PC. I have done some research about the
line "app = Dispatch("Word.Application")" and saw this:

http://www.programmingforums.org/post105986.html

The script described here is different comparing to what I want to do
but I might be able to use some ideas - of course, since Im not a
programmer, I need to study the functions before. On the link the user
is trying to replace parts (predefinited or not - i don't know) of
the .doc files - this is not moving/copying entire text but the topic
is still about writing something into .doc through python.
Unfortunatelly for me, his script doesn't need to search for
correct .doc file.

So I kept searching and came to this:

http://www.daniweb.com/forums/thread129924.html

This task is very close to what I want but still different. If we try
to compare;

"I am a text" (his task) = already exsisting (if any) text in my HDX
file where X is the highest number (my task)
"Hello" (his task) = whole text inside .doc with always the same name
on the same location (my task)

then thats it. I believe just those two differences exsist.

==============================================================================
TOPIC: Something More Elegant
http://groups.google.com/group/comp.lang.python/t/d88f8630a9cdd805?hl=en
==============================================================================

== 1 of 2 ==
Date: Sat, Jan 9 2010 10:00 am
From: Dennis Lee Bieber


On Sat, 9 Jan 2010 10:15:48 -0500, Victor Subervi
<victorsubervi@gmail.com> declaimed the following in
gmane.comp.python.general:

>
> And if you were in my shoes, I'm sure you'd do the same thing. Well, it *is*
> working now :)) And I am interested in cleaning this up. I should probably
> start with the matter of databases, since that's something I won't be able
> to easily change once clients actually start entering data. Please share
> with me any further concepts or questions to get me thinking how to redesign
> the databases.

That is a whole course by itself -- and a decent database design is
going to require you to replace some 90% of your current query design.
(And maybe 75% of any web interface you've currently hacked together)

http://www.google.com/#hl=en&source=hp&q=relational+database+normalization&aq=f&aqi=g3&oq=&fp=e8d6ef47431c6a4a
http://www.google.com/#hl=en&source=hp&q=relational+database+design&aq=0&aqi=g10&oq=relational+database+d&fp=e8d6ef47431c6a4a

Note that most database design work is done independent of the
database engine and access API (so things like injection attacks, and
query parameterization/optimization will not be covered during
design/analysis)

After the table design is complete you can move to business logic
operations (SQL for standard/fixed actions), along with criteria to
maintain the integrity of the data (foreign key constraints, etc.). This
should result in a set of SQL statements that are parameterized so that
only end-user data VALUES need to be supplied -- no ad hoc creation of
SQL by plugging in table names or column names (and especially no such
where the plugged in names were directly entered by the end-user -- I
acknowledge that there are some situations where generating SQL is
useful -- typically when you give the end user a dynamic search page*)

Then comes actually mapping the design and logic to the features of
the database engine in use: if an engine doesn't support cascade
operations on foreign keys, you have to code library routines to perform
the cascade yourself (suppose you "delete a 'store'" -- before you
perform that, you have to delete all inventory records associated with
the store -- cascading deletes on foreign keys will do that for you if
they are supported by the database engine). If you have to code such a
cascade you then have to determine if the engine supports "stored
programs" and "triggers" -- these would let you code the cascade in the
database itself so any access (even the DBA using a command line query
tool) will activate the emulated cascade. If those features are lacking,
you have to code the cascade at the application level (meaning every
application used to access the database will need to have some logic to
support cascades).


* Even for such, you NEVER accept table or field names as a string from
the end user -- instead you query the database schema to determine the
available names and present them in a menu format from which the user
makes selections. In a case of filtering a query you would obtain, via
menu, the table.field name, and a user supplied string for the
associated value. When building the SQL you would put in something like
(MySQL format)

SQL = """...
where
%s like %%s
AND %s like %%s #repeated for each field specified
""" % list_of_field_names_in_selected_order

params = ["%"+p+"%" for p in list_of_values_in_selected_order]
#this wraps the user parameters with SQL wildcards so the search
#term will match anywhere in the field

crs.execute(SQL, params)

(For SQLite, you'd use a single ? where MySQL is using %%s)




{Note: the web interface should not care what database engine is
being used -- it should just be given lists/tuples of data for
presentation, and return (if a form) simple data values (indices to menu
entries, user string VALUES, etc.) which are passed to the database
logic to create queries for the next display...}
--
Wulfraed Dennis Lee Bieber KD6MOG
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/

== 2 of 2 ==
Date: Sat, Jan 9 2010 10:00 am
From: Dennis Lee Bieber


On Sat, 9 Jan 2010 10:28:31 -0500, Victor Subervi
<victorsubervi@gmail.com> declaimed the following in
gmane.comp.python.general:

> On Sat, Jan 9, 2010 at 10:14 AM, Iuri <iurisilvio@gmail.com> wrote:
>
> > And you should use cursor.fetchall() instead of cursor in list
> > comprehension:
> >
> > packageIDs = [itm[0] for itm in cursor.fetchall()]
> >
>
> Now, someone else on this list told me the other. Can you explain the
> difference?

Since a (one-liner) list comprehension is going to result in
processing all the data, it may be faster to fetch all the data at the
start. Depending upon the implementation of the database API, iterating
over a cursor object to retrieve one record at a time may result in a
hit on the database engine (some engines may hold the data in the server
and only transmit it record by record unless explicitly asked for all of
it -- and if the database server is on a different machine that could
make for a lot of slow network traffic).

Also, you need to take the database locking system into account --
until you not only read all the data, but commit the transaction (even a
read-only transaction), the engine may lock any other user from
accessing those records (and some engines may lock the entire table, not
just records).

Iterating over a cursor may be useful if: 1) you have a really
massive database and your query is not filtering the data to manageable
levels (better done by looping over the query itself using limit and
offset features to control how many records are returned in a batch); 2)
it is a single user/single access database where locking data won't have
an impact; 3) you need to use the data in each record to update or
otherwise perform some other query on the database (though unless this
is done within the same transaction you might still have locking
issues).

--
Wulfraed Dennis Lee Bieber KD6MOG
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/


==============================================================================
TOPIC: Easy Q
http://groups.google.com/group/comp.lang.python/t/978a788bdaac2954?hl=en
==============================================================================

== 1 of 1 ==
Date: Sat, Jan 9 2010 10:02 am
From: Dave Angel


Victor Subervi wrote:
> Hi;
> I have a string.join statement on a variable that comes from a
> cgi.FieldStorage().getlist. The variable may be a list or a single value. I
> need to treat it differently depending on which it is. How can I distinguish
> it? len(var) will obviously give me the length of the string if it's a
> string and the length of the list if it's a list.
> TIA,
> beno
>
>
If you have to do an explicit type check of your variable, use an if
statement, and the isinstance() built-in function. Note that you can
check for multiple types, like list and tuple, in the same function call.


DaveA


==============================================================================
TOPIC: interactive terminal in Ubuntu Linux : libreadline5-dev works only in
Python 2.6 not 3.1
http://groups.google.com/group/comp.lang.python/t/e78273d8ffda71ae?hl=en
==============================================================================

== 1 of 4 ==
Date: Sat, Jan 9 2010 10:06 am
From: Dave WB3DWE


On Jan 6 I inquired how to "fix" the 3.1.1 interactive terminal
in Ubuntu Linux. Left arrow yields ^[[D , etc.

casevh helped by suggesting "libreadline5-dev" be installed.
Did so with Synaptic Package Manager.
The behavior of the Python 3.3.1 terminal is unchanged but
the 2.6.2 terminal is corrected.

Is there any way to fix the 3.1.1 terminal command line ?

Thanks, Dave WB3DWE pdlemper@earthlink.net


== 2 of 4 ==
Date: Sat, Jan 9 2010 1:27 pm
From: casevh


On Jan 9, 10:06 am, Dave WB3DWE wrote:
> On Jan 6 I inquired how to "fix" the 3.1.1 interactive terminal
> in Ubuntu Linux.   Left arrow yields ^[[D , etc.
>
> casevh helped by suggesting "libreadline5-dev" be installed.
> Did so with Synaptic Package Manager.
> The behavior of the Python 3.3.1 terminal is unchanged but
> the 2.6.2 terminal is corrected.
>
> Is there any way to fix the 3.1.1 terminal command line ?
>
> Thanks,     Dave WB3DWE      pdlem...@earthlink.net

Did you recompile Python 3.1.1 after installing libreadline5-dev?

(From the Python 3.1.1 directory. Your options to configure may vary.)

make distclean
./configure --prefix=/usr/local --with-computed-gotos --with-wide-
unicode
make
make altinstall

casevh


== 3 of 4 ==
Date: Sat, Jan 9 2010 3:10 pm
From: pdlemper@earthlink.net


On Sat, 9 Jan 2010 13:27:07 -0800 (PST), casevh <casevh@gmail.com>
wrote:

>
>Did you recompile Python 3.1.1 after installing libreadline5-dev?
>
>(From the Python 3.1.1 directory. Your options to configure may vary.)
>
>make distclean
>./configure --prefix=/usr/local --with-computed-gotos --with-wide-
>unicode
>make
>make altinstall
>
>casevh

Thanks so much for your help . . . but I'm going backwards, probably
due to my inadequate knowledge of Linux.

Ran the above vebatim, except had to do sudo make install .
Python recompiled and the system appears to be in same path/dir as
before : /home/dave/python31/Python-3.1.1
Called up interactive prompt >>> with $ python3 , as before.

Problems :
1. prompt keys remain fouled up as before.
2. will not import random module, either from prompt or
from any of my prewritten modules. Get ImportError
/usr/local/lib/Python3.1/lib-dynload/_collections.so :
undefined symbol : PyUnicode UCS4_FromString
Some other modules will import : math , sys, os
3. Some of my pre-existing modules will not run : have
not checked them all, but apparently those with random.
4. Attempted to read my modules with gedit. Pulls them
up but refuses to save : could not save file
/usr/local/lib/python3.1/dlmodules/Ackermann.py
You do not have permission necessary to save file.
This is same path my modules were in before the
recompile and the dir I made for them. Had no trouble
saving them previously.

If no fix available, I'll reinstall from the Python-3.1.1 that
I extracted from the tarball , and go back to XP for a while : (

Dave WB3DWE pdlemper@earthlink.net


== 4 of 4 ==
Date: Sat, Jan 9 2010 4:48 pm
From: casevh


On Jan 9, 3:10 pm, pdlem...@earthlink.net wrote:
> On Sat, 9 Jan 2010 13:27:07 -0800 (PST), casevh <cas...@gmail.com>
> wrote:
> >Did you recompile Python 3.1.1 after installing libreadline5-dev?
>
> >(From the Python 3.1.1 directory. Your options to configure may vary.)
>
> >make distclean
> >./configure --prefix=/usr/local --with-computed-gotos --with-wide-
> >unicode
> >make
> >make altinstall
>
> >casevh
>
> Thanks so much for your help . . . but I'm going backwards, probably
> due to my inadequate knowledge of Linux.
>
> Ran the above vebatim, except had to do      sudo make install    .
> Python recompiled and the system appears to be in same path/dir as
> before :  /home/dave/python31/Python-3.1.1
> Called up interactive prompt  >>>  with  $ python3 , as before.
>

It looks like you now have two copies of Python 3.1.1 installed.
That's probably a side-effect of my instructions. I'll got through
each instruction individually.

It looks like your Python source code is in "/home/dave/python31/
Python-3.1.1". The commnad "make distclean" should remove the results
of the prior configuration so to won't need to extract the source code
again.

The command "./configure" accepts several options that control how the
source code is configured. To see all the available options, use the
command "./configure --help". The first option - "--prefix=/usr/local"
- identifies the location where Python 3.1.1 will be installed. The "/
usr/local" directory is a common location for user-compiled programs.
If no location is specified, many applications assume "/usr/local".
The option - "--with-computed-gotos" - is just a compiler options that
produces a slightly faster interpreter. The final option - "--with-
wide-unicode" - identifies the proper Unicode format to use. (I looks
like this option may have been split via line wrapping on my earlier
email. I think it is causing the UCS4 error.)

The command "make" compiles Python 3.1.1.

The command "sudo make altinstall" installs Python 3.1.1 under the "/
usr/local" directory. The option "altinstall" installs Python 3.1.1
and leaves its name as "python3.1". It should be located in "/usr/
local/bin/python3.1".

Your own programs (Ackermann.py) should be kept somewhere in your home
directory, for example "/home/dave/code". Typing "python3.1" will look
in the current directory first, and then search the path where it
should find "/usr/local/bin/python3.1".

What will you need to do fix this?

1) Try the commands again. Make sure all the "./configure" options are
on one line. Make sure to do "sudo make altinstall". (Don't use "sudo
make install"; it will give your version of Python the name "python"
and that can cause confusion on your system.)

2) Move your applications to another directory.

3) Try running "python3.1" while you are in that directory.

If this doesn't work, report back on the error messages you receive.

Don't give up; we can fix this.

casevh
> Problems :
>     1. prompt keys remain fouled up as before.
>     2. will not import  random  module, either from prompt or
>             from any of my prewritten modules.  Get ImportError
>            /usr/local/lib/Python3.1/lib-dynload/_collections.so :
>             undefined symbol : PyUnicode UCS4_FromString
>                 Some other modules will import : math , sys, os
>     3. Some of my pre-existing modules will not run : have
>           not checked them all, but apparently those with random.
>     4. Attempted to read my modules with gedit.  Pulls them
>           up but refuses to save :          could not save file
>           /usr/local/lib/python3.1/dlmodules/Ackermann.py
>                You do not have permission necessary to save file.
>           This is same path my modules were in before the
>           recompile and the dir I made for them. Had no trouble
>           saving them previously.
>
> If no fix available, I'll reinstall from the Python-3.1.1 that
> I extracted from the tarball , and go back to XP for a while  : (
>
> Dave WB3DWE       pdlem...@earthlink.net


==============================================================================
TOPIC: lightweight encryption of text file
http://groups.google.com/group/comp.lang.python/t/b31a5b5f58084f12?hl=en
==============================================================================

== 1 of 4 ==
Date: Sat, Jan 9 2010 11:01 am
From: Daniel Fetchinson


>> I have a plain text file which I would like to protect in a very
>> simple minded, yet for my purposes sufficient, way. I'd like to
>> encrypt/convert it into a binary file in such a way that possession of
>> a password allows anyone to convert it back into the original text
>> file while not possessing the password one would only see the
>> following with the standard linux utility 'file':
>>
>> [fetchinson@fetch ~]$ file encrypted.data
>> encrypted.data: data
> [...]
>
> This is probably not what you want, but it is very simple and doesn't
> import any module:) I am not qualified to say how easy it is to discover
> the message without the password.
>
> def str2int(txt):
> return reduce(lambda n, c: n*255 + ord(c), txt, 0)
>
> def int2str(n):
> chars = []
> while n:
> n, o = divmod(n, 255)
> chars.append(chr(o))
> return ''.join(reversed(chars))
>
> def encrypt(txt, pwd):
> return int2str(str2int(txt)*str2int(pwd))
>
> def decrypt(txt, pwd):
> return int2str(str2int(txt)/str2int(pwd))
>
> def test(txt, pwd):
> encrypted_txt = encrypt(txt, pwd)
> decrypted_txt = decrypt(encrypted_txt, pwd)
> print "text:%r" % txt
> print "encrypted:%r" % encrypted_txt
> print "decrypted:%r" % decrypted_txt
>
>
>>>> test("This encryption scheme is definitely unbreakable.", "secret")
> text:'This encryption scheme is definitely unbreakable.'
> encrypted:'&2\xa5\xd4\x17i+E\x01k\xfa\x94\xf80\xa8\x8f\xea.w\x128\xf1\xd9\x0f9\xf2t\xc9\r`\x90%\xd6\xf3~\x1f\x00%u&\x8a\xe4\xe0\xa7\xb8\xb0ec)S>\xcb\xf2>\xec'
> decrypted:'This encryption scheme is definitely unbreakable.'

Thanks, this looks pretty simple too, I will go with either Steven's
or with your solution.

Cheers,
Daniel

--
Psss, psss, put it down! - http://www.cafepress.com/putitdown


== 2 of 4 ==
Date: Sat, Jan 9 2010 12:03 pm
From: Paul Rubin


Daniel Fetchinson <fetchinson@googlemail.com> writes:
> I have a plain text file which I would like to protect in a very
> simple minded, yet for my purposes sufficient, way.

For encrypting strings, use this module:

http://nightsong.com/phr/crypto/p3.py

Obviously this is limited to strings that fit in memory, which
might be a problem with large files. Some day I might get
around to adding a streaming interface to it.

The "file" command will not recognize the ciphertext as encrypted
data. It will just say "data".

If you want to be more serious, use pgp or gpg with the -c option
(password-based encryption). I think "file" does recognize the pgp
file format as encrypted data (RFC 2440).


== 3 of 4 ==
Date: Sat, Jan 9 2010 12:04 pm
From: Paul Rubin


Daniel Fetchinson <fetchinson@googlemail.com> writes:
>> http://www.nightsong.com/phr/crypto/p3.py
>
> Thanks a lot, currently I'm having trouble using this code on python
> 2.6 but probably some small tweaking will fix it.

Yikes, this is the first I've heard of such a problem. I will
look into it. Thanks. (Also thanks to Robert for the recommendation).


== 4 of 4 ==
Date: Sat, Jan 9 2010 12:18 pm
From: Paul Rubin


Robert Kern <robert.kern@gmail.com> writes:
> Are you on a 64-bit platform? Unfortunately, array's integer typecodes
> are platform-specific, but p3.py requires a 32-bit integer ...

Oh yes, thanks, I never did get around to dealing with 64 bit platforms.
I also notice that some of the unit test functions use print statements,
which won't compile under Python 3.0. I will try to release a version
in the next few days with fixes for both of these issues.

==============================================================================
TOPIC: Scripting (was Re: Python books, literature etc)
http://groups.google.com/group/comp.lang.python/t/6ad7a20513065f9f?hl=en
==============================================================================

== 1 of 1 ==
Date: Sat, Jan 9 2010 11:19 am
From: "bartc"

"Peter" <vmail@mycircuit.org> wrote in message
news:mailman.661.1262978839.28905.python-list@python.org...
>
>> Sounds good.
>>
>> Regarding the book's title: is it just me, or are Python programmers
>> in general put off when people call it "scripting"?
>>
>> I won't attempt a strict definition of the term "scripting language",
>> but it seems like non-programmers use it to mean "less scary than what
>> you might think of as programming", while programmers interpret it as
>> "not useful as a general-purpose language".
>>
>>
> It took me a while to take "scripting" seriously. I grew up with Pascal
> and Eiffel and I found it difficult to appreciate dynamic typing and
> scripting. The author Langtangen is explaining in detail why he considers
> scripting useful, in particular he provides an automatic test suite to run
> different language versions ( perl, python, c, c++) of the same program to
> compare performance. The results are amazing, in that some of the examples
> run faster than the C++ version.

I think if you can get Python to run fast (compared to compiled languages),
then that's scripting (ie. just using it to sequence lots of built-in
functions and operations).

If it runs a lot slower than those other languages, then you're probably
doing some programming.

And with programs where the runtime is not significant, it could be
either...

--
Bartc


==============================================================================
TOPIC: PIL show() not working for 2nd pic
http://groups.google.com/group/comp.lang.python/t/faa125f29fd5fe93?hl=en
==============================================================================

== 1 of 1 ==
Date: Sat, Jan 9 2010 11:52 am
From: Cousin Stanley

> I am using PIL for image processing in ubuntu 9.04. When i give two
> im.show() commands for two different images, the second image is not
> displayed (eye of gnome is the display program). It says no such file
> or directory. Any ideas?

Suresh ....

I also had problems with show() when using eye of gnome
as the image viewer with your code but no problems using
the display viewer from the imagemagick package ....

im.show( command = 'eog' ) # problems
im.show( command = 'display' ) # no problems

# ----------------------------------------------------------

#!/usr/bin/python

'''
NewsGroup .... comp.lang.python
Subject ...... PIL show() not working for 2nd pic
Date ......... 2010-01-07
Post_By ...... suresh.amritapuri
Edit_By ...... Stanley C. Kitching
'''

import math
import Image

list_source = [
'image/beach.tif' ,
'image/colors.tif' ]

list_target = [ ]

def neg( x ) :
return 255 - 1 - x

def logtr( x ) :
y = math.log( 1 + x , 10 )
print y
return y * 100

for this_image in list_source :
im_source = Image.open( this_image )
im_neg = im_source.point( neg )
im_logtr = im_source.point( logtr )

list_target.append( im_source )
list_target.append( im_neg )
list_target.append( im_logtr )

for this_image in list_target :
this_image.show( command = 'display' )

# ----------------------------------------------------------

--
Stanley C. Kitching
Human Being
Phoenix, Arizona


==============================================================================
TOPIC: [RELEASED] Python 2.7 alpha 2
http://groups.google.com/group/comp.lang.python/t/f1c68d96f3e86f41?hl=en
==============================================================================

== 1 of 3 ==
Date: Sat, Jan 9 2010 11:53 am
From: "Jan Kaliszewski"


Hello,

I have a question: are class decorator planned to be backported from 3.x?

All the best,
*j
--
Jan Kaliszewski (zuo) <zuo@chopin.edu.pl>


== 2 of 3 ==
Date: Sat, Jan 9 2010 1:34 pm
From: Jack Diederich


On Sat, Jan 9, 2010 at 2:53 PM, Jan Kaliszewski <zuo@chopin.edu.pl> wrote:
> Hello,
>
> I have a question: are class decorator planned to be backported from 3.x?
>
Eh? Class decorators have been in the 2.x series since 2.6.

If you want to know more about class decorators check out this talk
from PyCon 2009 http://pycon.blip.tv/file/1949345 by a very handsome
and well beloved man, and come to pycon 2010 where there will be a
couple more talks on the subject by slightly more homely but none the
less competent speakers.

-Jack


== 3 of 3 ==
Date: Sat, Jan 9 2010 1:44 pm
From: "Jan Kaliszewski"


09-01-2010 o 22:34:28 Jack Diederich <jackdied@gmail.com> wrote:

> On Sat, Jan 9, 2010 at 2:53 PM, Jan Kaliszewski <zuo@chopin.edu.pl>

>> I have a question: are class decorator planned to be backported from
>> 3.x?
>>
> Eh? Class decorators have been in the 2.x series since 2.6.

Oops, I overlooked the fact :) Thank you!

*j

--
Jan Kaliszewski (zuo) <zuo@chopin.edu.pl>

==============================================================================
TOPIC: Link to module Stack
http://groups.google.com/group/comp.lang.python/t/5f7014f20243d059?hl=en
==============================================================================

== 1 of 2 ==
Date: Sat, Jan 9 2010 12:31 pm
From: Steve Holden


Steven D'Aprano wrote:
> On Sat, 09 Jan 2010 05:56:36 -0500, Dave Angel wrote:
>
>>> "InnerInterpreterError" is the most inappropriate exception name I've
>>> ever seen. It has nothing to do with the interpreter, it's a stack
>>> error.
>>>
>>>
>> It has everything to do with the (Forth) interpreter. Exceptions can
>> readily be named according to their application -- it's not always about
>> Python. Anyway, Forth has an inner-interpreter and an
>> outer-interpreter, and the name will make sense to a Forth programmer.
>
> Pardon me, but I *am* a Forth programmer. Or was, it's been many years,
> and I'm rusty. I guess this is a difference of terminology: what you're
> calling an inner interpreter and an outer interpreter I know of as the
> Forth engine and the (text) interpreter. Gforth refers to them as such,
> so did Leo Brodie's Forth books, and the (ancient) Macintosh Forth
> compiler "Mach 2".
>
> But in any case... a stack is an general-purpose data structure, and the
> error message shouldn't be coupled so tightly to one use. That would be
> like this (made-up) example:
>
>>>> 1/0
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> GraphicsApplicationError: too few pixels to calculate average
>
>
> Ridiculous, yes?
>
>
> Yes, Forth uses a stack (technically two, a parameter stack and a return
> stack, and some implementations include a third, floating point, stack).
> Virtually all languages use stacks in their implementation, and Python
> byte-code is also stack-based.
>
>
>>>> result = self.__heap[-1]
>>>> del self.__heap[-1]
>>>>
>>>>
>>> That is better written as result = self.__heap.pop().
>>>
>>>
>>>
>> or even better, without the extra local var:
>>
>> def pop (self):
>> if len(self.__heap) == 0:

Since self.__heap is a list, the canonical Python for the above test
would, of course, be the much simpler

if not self.__heap

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/
Holden Web LLC http://www.holdenweb.com/
UPCOMING EVENTS: http://holdenweb.eventbrite.com/

== 2 of 2 ==
Date: Sat, Jan 9 2010 4:17 pm
From: Dave Angel


Steven D'Aprano wrote:
> On Sat, 09 Jan 2010 05:56:36 -0500, Dave Angel wrote:
>
>
>>> "InnerInterpreterError" is the most inappropriate exception name I've
>>> ever seen. It has nothing to do with the interpreter, it's a stack
>>> error.
>>>
>>>
>>>
>> It has everything to do with the (Forth) interpreter. Exceptions can
>> readily be named according to their application -- it's not always about
>> Python. Anyway, Forth has an inner-interpreter and an
>> outer-interpreter, and the name will make sense to a Forth programmer.
>>
>
> Pardon me, but I *am* a Forth programmer. Or was, it's been many years,
> and I'm rusty. I guess this is a difference of terminology: what you're
> calling an inner interpreter and an outer interpreter I know of as the
> Forth engine and the (text) interpreter. Gforth refers to them as such,
> so did Leo Brodie's Forth books, and the (ancient) Macintosh Forth
> compiler "Mach 2".
>
>
I'm pretty sure FIG-Forth called them an inner interpreter and outer
interpreter, but I don't remember other sources. FIG-Forth was my first
Forth system, gotten on an 8" diskette. The inner interpreter was
LOADSW, JMP AX, I believe, as it was an indirected threaded interpreter
implementation.

> <snip>
>
>> or even better, without the extra local var:
>>
>> def pop (self):
>> if len(self.__heap) == 0:
>> raise InnerInterpreterError, "stack underflow"
>> return self.__heap.pop(1)
>>
>
> pop(1)? I don't think so.
>
>
>
That was a typo; I meant pop(). And of course others have improved on
my remarks anyway.

DaveA

==============================================================================
TOPIC: Append to an Excel file
http://groups.google.com/group/comp.lang.python/t/6e21b15ce9abeb32?hl=en
==============================================================================

== 1 of 1 ==
Date: Sat, Jan 9 2010 2:33 pm
From: niels.ellegaard@gmail.com (Niels L. Ellegaard)


pp <parul.pandey85@gmail.com> writes:

> On Jan 9, 1:47 am, Jason Scheirer <jason.schei...@gmail.com> wrote:
>> On Jan 9, 12:30 am, pp <parul.pande...@gmail.com> wrote:
>>
>> > Hi All,
>>
>> > How do I add a line to an existing file. This should append to the
>> > existing data in the excel file, which was saved previously.
>>
>> > Thanks,
>> > PP
>>
>> http://pypi.python.org/pypi/xlwt
>
> Hi Jason and all,
>
> Thanks
>
> I have seen this.. my question is there a way to append to a excel
> file which has been closed. Any specific modes which can be added to
> the sheet so that it adds a line to the data which was return in some
> earlier running of the program.

I may be wrong, but I think that you have to do the following

1) Use xlrd to read the file. This creates an xlrd.Book
2) Use xlutils to transform the xlrd.Book into a xlwt.WorkBook
3) Edit the xlwt.WorkBook
4) Save the xlwt.WorkBook

https://secure.simplistix.co.uk/svn/xlutils/trunk/xlutils/docs/copy.txt

Niels


==============================================================================
TOPIC: Prepend to logging message
http://groups.google.com/group/comp.lang.python/t/dda048a92c122117?hl=en
==============================================================================

== 1 of 1 ==
Date: Sat, Jan 9 2010 5:01 pm
From: Joan Miller


How to prepend anything to a logging message? Is possible to do it
from the dictionary object (ExtraLog) or is there is that override
process() [1]?

------------------
class ExtraLog(object):

def __getitem__(self, name):
if name == 'foo':
result = 'testing'
return result

def __iter__(self):
keys = ['foo',]
keys.extend(self.__dict__.keys())
return iter(keys)

logger = logging.LoggerAdapter(logging.getLogger('foo'), ExtraLog())
------------------


[1] http://docs.python.org/library/logging.html#logging.LoggerAdapter


==============================================================================

You received this message because you are subscribed to the Google Groups "comp.lang.python"
group.

To post to this group, visit http://groups.google.com/group/comp.lang.python?hl=en

To unsubscribe from this group, send email to comp.lang.python+unsubscribe@googlegroups.com

To change the way you get mail from this group, visit:
http://groups.google.com/group/comp.lang.python/subscribe?hl=en

To report abuse, send email explaining the problem to abuse@googlegroups.com

==============================================================================
Google Groups: http://groups.google.com/?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate