Re: Should I Learn Python or Ruby next?

2010-06-22 Thread Michael Crute
On Tue, Jun 22, 2010 at 4:58 AM, Josef Tupag  wrote:
> I've been programming (when I do program) mainly in Perl for the last 10
> years or so. But I've been itching to learn a new language for a while now,
> and the two near the top of the list are Ruby and Python.

If you have the time give both a try. Start with Python, of course
;-). I've been programming Python as my primary language for the past
4 years after having done Perl and PHP professionally. Python is a lot
of fun, the language is very clean and clear and it's got a great
standard library. From my dabbling in Ruby I can say that I'm not too
keen on the syntax of the language or some of the semantics, it just
feel sloppy (but certainly less sloppy than PHP). Both languages are
very functional and you can do the same tasks in either one so I think
it comes down, mostly, to syntax and semantics.

-- 
Michael E. Crute
http://mike.crute.org

It is a mistake to think you can solve any major problem just with
potatoes. --Douglas Adams
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What module to parse/generate ical files?

2010-06-21 Thread Michael Crute
On Mon, Jun 21, 2010 at 1:50 PM, Grant Edwards  wrote:
> What module is recommended for parsing/generating ical files?
>
> However, I'm not sure it's being maintained.  Despite the claim on the
> above page that the current version is 2.1, The latest version I can
> find is v1.2 from 2006.

I've had pretty good luck with iCalendar, I'm currently using it to
bridge Outlook Web Access to iCal for old versions of Exchange and it
works flawlessly.

-- 
Michael E. Crute
http://mike.crute.org

It is a mistake to think you can solve any major problem just with
potatoes. --Douglas Adams
-- 
http://mail.python.org/mailman/listinfo/python-list


Standard Library SSL Module (was: Python OpenSSL library)

2010-06-14 Thread Michael Crute
On Mon, Jun 14, 2010 at 1:25 PM, Antoine Pitrou  wrote:
> That was not my question. My question was whether there was a reason to
> rewrite a separate OpenSSL-accessing library rather than contributing to
> improve the "hashlib" and "ssl" modules which are already part of the
> Python stdlib.

The ssl module in the standard library is currently just SSL wrappers
around sock objects while M2Crypto, PyCrypto and Evpy are all a more
complete implementation of the other cryptography and signing features
in OpenSSL. I think it would be really awesome to have a complete
OpenSSL wrapper in the Python standard library since crypto in Python
is somewhat of a pain today. If I wanted to work on something like
that what would be the best approach? Extend the ssl package? Create a
new crypto package?


-- 
Michael E. Crute
http://mike.crute.org

It is a mistake to think you can solve any major problem just with
potatoes. --Douglas Adams
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python OpenSSL library

2010-06-13 Thread Michael Crute
On Sun, Jun 13, 2010 at 5:59 PM, astral
 wrote:
>> You might want to take a look at m2crypto[0]. While I have not
>> personally run it on Windows (runs great on OS X and Linux) they do
>> provide pre-compiled Windows binaries.
>
> which one is for windows, for Python version 2.5.4 ? And how to uninstall
> when required?

I don't use windows so I can't help you with Windows specific
questions. The windows downloads are clearly marked for python 2.4,
2.5 and 2.6. Go back and read the entire page.

-- 
Michael E. Crute
http://mike.crute.org

It is a mistake to think you can solve any major problem just with
potatoes. --Douglas Adams
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python OpenSSL library

2010-06-13 Thread Michael Crute
On Sun, Jun 13, 2010 at 4:29 PM, astral
 wrote:
> I am looking for Python OpenSSL library, for Python version 2.5.4 (on
> Windows)
> Which does not require to install Cygwin package. Need just to decrypt file,
> then uninstall library.

You might want to take a look at m2crypto[0]. While I have not
personally run it on Windows (runs great on OS X and Linux) they do
provide pre-compiled Windows binaries.

[0] http://chandlerproject.org/bin/view/Projects/MeTooCrypto


-- 
Michael E. Crute
http://mike.crute.org

It is a mistake to think you can solve any major problem just with
potatoes. --Douglas Adams
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pythonic ssh

2010-05-17 Thread Michael Crute
On Mon, May 17, 2010 at 9:37 AM, John Maclean  wrote:
> pyssh, pexpect, paramiko or creating your your own sockets. what do you use
> to pythonically ssh to boxes?

I think the answer to this depends on your goals. Paramiko is the best
way to go if you want a pythonic API to ssh but you also will
introduce a dependency on paramiko and a transitive dependency on
pycrypto (which requires openssl). I personally prefer to just use
subprocess with the ssh binary for most of my scripts because it
doesn't introduce any extra dependencies and is relatively easy to
implement. pyssh tries to wrap up the common ssh patterns using
os.popen but it hasn't been maintained in several years so your best
bet is probably to stick with using subprocess if you don't go with
paramiko.

-- 
Michael E. Crute
http://mike.crute.org

It is a mistake to think you can solve any major problem just with
potatoes. --Douglas Adams
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Two questions ( Oracle and modules )

2009-12-07 Thread Michael Crute
On Mon, Dec 7, 2009 at 6:57 AM, Gabor Urban  wrote:
> 1. I have choice to introduce Python to my new employee. We are to
> write and application that uses databases stored partially in Oracle
> 10 and partially in Oracle 11. We have to execute standard SQL
> commands and stored procedures as well. Which is best conection /
> module to use. A couple of years ago we had DCOracle2 for the same
> task, but is written for Oracle8, so I gues it might not be a good
> idea to use. What is your oppinion?

cx_Oracle is the best way to connect to Oracle databases, DCOracle2
hasn't been maintained in some time. http://cx-oracle.sourceforge.net/

-mike

-- 
Michael E. Crute
http://mike.crute.org

It is a mistake to think you can solve any major problem just with
potatoes. --Douglas Adams
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Code in __init__.py, is it bad form?

2009-02-23 Thread Michael Crute
On Mon, Feb 23, 2009 at 9:41 PM, Benjamin Peterson  wrote:
> Michael Crute  gmail.com> writes:
>> On Mon, Feb 23, 2009 at 9:03 PM, Steve Holden  holdenweb.com> 
>> wrote:
>> > No, it's absolutely fine. One common usage is to import symbols from
>> > sub-modules so that they are available from a simple import of the package.
>>
>> Yeah, I use it often for that I'm talking more about stuff like
>> utility functions, main methods, etc...
>
> There's no overarching Python doctrine forbidding you to do it. It has simply
> become a matter of taste. Personally, I tend to put utility functions in their
> own module (eg. util), but I do use __init__ for main methods and such.

Okay, so assuming I have decent judgment it sounds like I'm not doing
anything patently wrong. Thanks for the input.

-mike

-- 

Michael E. Crute
http://mike.crute.org

God put me on this earth to accomplish a certain number of things.
Right now I am so far behind that I will never die. --Bill Watterson
--
http://mail.python.org/mailman/listinfo/python-list


Re: Code in __init__.py, is it bad form?

2009-02-23 Thread Michael Crute
On Mon, Feb 23, 2009 at 9:03 PM, Steve Holden  wrote:
> Michael Crute wrote:
>> Is it bad form (i.e. non-pythonic) to have code in your __init__.py
>> files? I know this is subjective so I'm just looking for the general
>> consensus. I've heard both sides of the story and I personally feel
>> its okay if the code pertains to the whole module but have an open
>> mind about the matter. If you object to code in __init__.py why, and
>> what alternatives do you propose?
>>
> No, it's absolutely fine. One common usage is to import symbols from
> sub-modules so that they are available from a simple import of the package.

Yeah, I use it often for that I'm talking more about stuff like
utility functions, main methods, etc...

-mike

-- 

Michael E. Crute
http://mike.crute.org

God put me on this earth to accomplish a certain number of things.
Right now I am so far behind that I will never die. --Bill Watterson
--
http://mail.python.org/mailman/listinfo/python-list


Code in __init__.py, is it bad form?

2009-02-23 Thread Michael Crute
Is it bad form (i.e. non-pythonic) to have code in your __init__.py
files? I know this is subjective so I'm just looking for the general
consensus. I've heard both sides of the story and I personally feel
its okay if the code pertains to the whole module but have an open
mind about the matter. If you object to code in __init__.py why, and
what alternatives do you propose?

-- 

Michael E. Crute
http://mike.crute.org

God put me on this earth to accomplish a certain number of things.
Right now I am so far behind that I will never die. --Bill Watterson
--
http://mail.python.org/mailman/listinfo/python-list


Re: Importing Version Specific Modules

2008-12-04 Thread Michael Crute
On Thu, Dec 4, 2008 at 7:33 PM,  <[EMAIL PROTECTED]> wrote:
>Michael> try:
>Michael> from string import Template
>Michael> except ImportError:
>Michael> from our.compat.string import Template
>
> This is "easier to ask forgiveness than permission" (EAFP).  This tends to
> be more Pythonic (and thus, preferred).  You don't *really* care what the
> version just, but whether or not the string module has a Template object.
> Besides, what if some bright admin at some customer decides to backport the
> Template implementation to their 2.4 installation?  The first form would
> load your compatibility version, probably not what they were hoping when
> they put in the effort to backport.

That was the kind of reasoning I'm looking for. I'll stick with the
pythonic try/except approach then.

-mike

-- 

Michael E. Crute
http://mike.crute.org

God put me on this earth to accomplish a certain number of things.
Right now I am so far behind that I will never die. --Bill Watterson
--
http://mail.python.org/mailman/listinfo/python-list


Importing Version Specific Modules

2008-12-04 Thread Michael Crute
Which method makes the most sense for importing a module in python
that is version specific? My use case is that I'm writing code that
will be deployed into a python 2.3 environment and in a few months be
upgraded to python 2.5. This:

if sys.version_info[:2] >= (2, 5):
from string import Template
else:
from our.compat.string import Template

or this

try:
from string import Template
except ImportError:
from our.compat.string import Template

I know that either case is equally correct and works correctly but
which one is preferable?


-- 

Michael E. Crute
http://mike.crute.org

God put me on this earth to accomplish a certain number of things.
Right now I am so far behind that I will never die. --Bill Watterson
--
http://mail.python.org/mailman/listinfo/python-list


Re: 'new' module deprecation in python2.6

2008-11-29 Thread Michael Crute
On Sat, Nov 29, 2008 at 11:52 AM, David Pratt <[EMAIL PROTECTED]> wrote:
> Can someone tell me why 'new' has been deprecated in python 2.6 and provide
> direction for code that uses new for the future.
> I find new is invaluable for some forms of automation. I don't see a
> replacement for python 3 either. Many thanks.

You might want to take a look at PEP 3108[1] which says:

new

* Just a rebinding of names from the 'types' module.
* Can also call type built-in to get most types easily.
* Docstring states the module is no longer useful as of revision
27241 (2002-06-15).

[1] http://www.python.org/dev/peps/pep-3108/

-mike


-- 

Michael E. Crute
http://mike.crute.org

God put me on this earth to accomplish a certain number of things.
Right now I am so far behind that I will never die. --Bill Watterson
--
http://mail.python.org/mailman/listinfo/python-list


Re: Web programming in Python.

2008-09-28 Thread Michael Crute
On Sun, Sep 28, 2008 at 6:39 PM, Kurda Yon <[EMAIL PROTECTED]> wrote:
> I am totaly newbie in the Python's web programming. So, I dont even
> know the basic conceptions (but I have ideas about php-web-
> programming). Does it work in a similar way? First, I have to install
> a Python-server?

There are a couple of different ways to do web development in python.
The easiest if you're familiar with web development in other languages
is through CGI. I would recommend reading up on the python cgi module
[1] which will walk you through the basics of writing your first cgi
program. When you're comfortable with basic cgi you might want to look
into a framework like Django or CherryPy.

-mike

[1] http://docs.python.org/lib/module-cgi.html

-- 

Michael E. Crute
http://mike.crute.org

God put me on this earth to accomplish a certain number of things.
Right now I am so far behind that I will never die. --Bill Watterson
--
http://mail.python.org/mailman/listinfo/python-list


Re: check if file is MS Word or PDF file

2008-09-27 Thread Michael Crute
On Sat, Sep 27, 2008 at 7:01 PM, Chris Rebert <[EMAIL PROTECTED]> wrote:
> Looking at the docs for the mimetypes module, it just guesses based on
> the filename (and extension), not the actual contents of the file, so
> it doesn't really help the OP, who wants to make sure their program
> isn't misled by an inaccurate extension.

One other way to detect a pdf is to just read the first 4 bytes from
the file. Valid pdf files start with "%PDF-". Something similar can be
done with Word docs but I don't know what the magic bytes are. This
approach is pretty similar to what the file command does but is
probably a better approach if you have to support multiple platforms.

-mike

-- 

Michael E. Crute
http://mike.crute.org

God put me on this earth to accomplish a certain number of things.
Right now I am so far behind that I will never die. --Bill Watterson
--
http://mail.python.org/mailman/listinfo/python-list


Re: check if file is MS Word or PDF file

2008-09-27 Thread Michael Crute
On Sat, Sep 27, 2008 at 5:43 PM, A. Joseph <[EMAIL PROTECTED]> wrote:
> What should I look for in a file to determine whether or not it is a
> MS Word file or an Excel file or a PDF file, etc., etc.? including Zip
> files
>
> I don`t want to check for file extension.
> os.path.splitext('Filename.jpg') will produce a tuple of filename and
> extension, but some file don`t even have extension and can still be read by
> MS Word or NotePad. i want to be 100% sure of the file.

You could use the mimetypes module...

<<< import mimetypes
<<< mimetypes.guess_type("LegalNotices.pdf")
>>> ('application/pdf', None)

-mike

-- 

Michael E. Crute
http://mike.crute.org

God put me on this earth to accomplish a certain number of things.
Right now I am so far behind that I will never die. --Bill Watterson
--
http://mail.python.org/mailman/listinfo/python-list