[Tutor] Search for hex data in file

2009-05-24 Thread xbmuncher
I've been reading about ways to convert strings and what not to hex and back
and forth. I'm looking for the fastest and least memory intensive way to
search through a file for a hex value and gets its byte offset in the file.
This hex value (that I'm looking for in the file) is of course a hex
representation of the binary data and its 8 bytes long.
I figured reading the whole file and converting it to hex from ascii..etc..
would be overkill, especially if its a large file.
What do you guys recommend? I want to search the file for certain hex value
and get the byte offset within the file.

Thanks for reading.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Find a good linux distribution with python.

2009-05-24 Thread Walker Hale IV
On Sun, May 24, 2009 at 4:44 PM, Alan Gauld  wrote:
> "Michael Bernhard Arp Sørensen"  wrote
> Most folks get by with the standard libraryb and a small number of
> specialist modules to meet their specific needs. If you need a new
> one install it, but loading lots of stuff just because its there is just a
> waste of disk space IMHO.
>
>> create my own python repo to set up a good working environment for
>> development. That way I could use any distro.
>
> By defaulyt Python keeps all its installed packages in the Python
> directory structure so, effectively, you do build up your own repo. But
> don't do it in advance just add to it as you need to.
>
>> On the other hand, any code I might write would be difficult
>> for others to use.
>
> If you stick to the a standard Python package tools it should be fine.
> Not just on Linux but on any other OS too.
>
>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/

I agree with Alan. These days the trend seems to be in the opposite direction.

I'm seeing developers keeping a "clean" Python environment and then
installing additional packages into virtual environments. That keeps
conflicts to a minimum and solves the problem of uninstalling unwanted
packages.

http://pypi.python.org/pypi/virtualenv

Some developers even go so far as putting their Python environment
under version control using something like Bazaar, git, or Mercurial
(alphabetical order). This is in an effort to keep the contents of
their Python environment under control.

Once you have setuptools installed, it just too easy to type
"easy_install spam" and get that package installed into your
environment. The challenge is to control clutter in your environment.

http://pypi.python.org/pypi/setuptools

If you can keep your dependencies under control, then you can give
users a reasonable set of requirements. If necessary, you can bundle
things up for end users:

http://www.py2exe.org/
http://svn.pythonmac.org/py2app/py2app/trunk/doc/index.html
http://pypi.python.org/pypi/zc.buildout

On the other hand, I do believe that Python needs an expanded distro
for developers, but it would only contain a few extra things, such as
the items mentioned above.

-- 
Walker Hale 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] strings using Czech language characters

2009-05-24 Thread vy
 [ wish to make a dictionary of english to czech words / Unsupported
characters in input / ISO-8859-2 ]

have a look at the manual, in my case, section 4.9.2 on stand
encodings p. 149 of the 2.4.3 (lib.pdf) Python Library Reference and
at the python prompt try

>>> help('modules codecs')

-- vy
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Find a good linux distribution with python.

2009-05-24 Thread Alan Gauld


"Michael Bernhard Arp Sørensen"  wrote


I'm on an eternal quest to find the perfect linux distro


Don't wste your time. The distro doesn't make much difference beyond:

- The basic file system structure and if it sticks to (one of) the standard
then thats not a big issue

- The package manager - you may prefer apt-get or yast or rpm or whatever

- the installer, but you only use it once (sort of!)


I've used Slackware, Redhat, Mandrake/Mandiva, Suse, Debian(briefly!)
and a couple of lesser known ones. Once they were up and trunning I
didn't find much difference with any of them!


Therefore there's a lot of python stuff in the repository.


The beauty of Python is that because it is platform independant
it is also distro independant. Thus if you dowenloasd a python
package and install it it will work regardless of distro.

Another point: There's so many modules on the Internet, that it's 
difficult

to get some sort of overview.


Most folks get by with the standard libraryb and a small number of
specialist modules to meet their specific needs. If you need a new
one install it, but loading lots of stuff just because its there is just a
waste of disk space IMHO.


create my own python repo to set up a good working environment for
development. That way I could use any distro.


By defaulyt Python keeps all its installed packages in the Python
directory structure so, effectively, you do build up your own repo. But
don't do it in advance just add to it as you need to.


On the other hand, any code I might write would be difficult
for others to use.


If you stick to the a standard Python package tools it should be fine.
Not just on Linux but on any other OS too.


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



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] A few very basic questions

2009-05-24 Thread Alan Gauld

"M Tramp"  wrote

I've started trying ot learn about Python because ... Gramps, a 
genealogical

To run Gramps on a Mac, I need to get GTK up and running.


Have you checked fink? There's a MacOS Gimp toolkit package available.
(Well 3 actually, gtk, gtk-data and gtk-shlibs) I generally use fink 
rather than

try apt-get because I know the fink stuff is tested against MacOS. And fink
packages are pre-built usually...


(FYI, I have a Mac, running OS X 10.4.11. Xcode 2.5)


1) GTK has several dependencies, according to 
http://library.gnome.org/devel/gtk-faq/stable/c192.html

... pkg-config; GNU make; JPEG, PNG and TIFF image libraries;


These should all be in place already

FreeType; fontconfig; GNU libiconv library; GNU gettext; GLib; Pango; 
ATK.


Not so sure about these though.


Each of these may have dependencies as well. Is there someplace to
go to figure out the order they should be compiled?


apt-get should sort most of that out for you, it checks depemdencies and
dependencies on dependencies etc. And if they are apt-get packages
they should be either pre bu8ilt or apt-get should initiate the builds for
you (I think, its been a while since I used it!)


2) Once each library is compiled, what should I have and where
should it be on my hard drive?


Using make (either directly or via apt-get) should sort that out.


For example, when Python sees "import gtk" in which directory is
it looking for GTK?


Thats a different question because you need pygtk too and Python
looks for the pygtk file which in turn looks for the real gtk library...
And that should be a standard place that make knows about.


How will GTK and the other libraries appear on my hard disk?
As Unix executables or as frameworks or as something else entirely?


In normal Unix it would be as libraries but under MacOS its
entirely possible they show up as a Framework...


3) I am likely to do my Python programming inside Eclipse using
pydev, though I have Xcode.


In my experience Eclipse is a better option than XCode unless
you are doing Aqua GUI programming XCode is great for Objective C
but I never liked it for Python.


The libraries will be in C, correct?


Yes, mostly, some of the pygtk stuff may be in python.


Will I be able to use Xcode to compile GTK and the rest,
and then access the libraries inside Eclipse?


You should be able to. You may have to set up some paths in Eclipe's
preferences.

HTH,

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



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Find a good linux distribution with python.

2009-05-24 Thread bhaaluu
On Sun, May 24, 2009 at 4:02 PM, Michael Bernhard Arp Sørensen
 wrote:
>
> What distro do you run?
>

Debian GNU/Linux

>
> Another point: There's so many modules on the Internet, that it's difficult
> to get some sort of overview. That's why a distro is such a great idea
> because so many packages with python stuff is included. Could you get any
> kind of overview over python modules/libs other than a repo in a distro?
>

Like anything else that is huge, just tackle the parts of it that you need.

>
> I have concluded that there's no such thing as a perfect distro. Only some
> distros come close to perfection. In that case I was wondering if I should
> create my own python repo to set up a good working environment for
> development. That way I could use any distro. On the other hand, any code I
> migth write would be difficult for others to use.
>
> Any ideas or comments?
>

"Ubuntu" is an African word that means "I can't configure Debian."
8^D
Knoppix, Ubuntu, and several other distributions are all based on
the fine work that the Debian GNU/Linux community does. Debian
GNU/Linux is completely Free, and is developed by volunteers from
around the world.

>
> I use emacs with rope, ipython and python. I like those in newer versions if
> not bleeding edge.
>

If you're really serious about having the 'perfect' distro, you can start
with Debian GNU/Linux and make your own, the way you want it to be.
While it is not a trivial matter to re-master a Linux Live CD, it is much
easier than it used to be! You could pack it full of Python! It is this
reason that there are hundreds of Linux Live CD distributions. Each
person thinks that their distro is the best. This is one reason why
GNU/Linux is so fantastic!

> Med venlig hilsen/Kind regards
>
> Michael B. Arp Sørensen
> Programmer / BOFH
> Denmark
>
> "If you want to enter my network while I'm out, you can find my SSH-key
> under my mouse mat" - Michael Bernhard Arp Sørensen
>

Why don't you make a Python-centric Linux Live CD?
-- 
b h a a l u u at g m a i l dot c o m
Kid on Bus: What are you gonna do today, Napoleon?
Napoleon Dynamite: Whatever I feel like I wanna do. Gosh!
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] serious problem with graphics module

2009-05-24 Thread roberto
hello everyone
i have a problem with python 3.0 graphics module:

no problem while importing the module
>>> import turtle

but when i issue any command like:
>>> t = turtle.pen()
>>> t = turtle.forward(60)

nothing appears on the screen, only a blank window, with nothing inside;
may you give me some hint ?


OS: win Xp

thank you in advance !

-- 
roberto
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Find a good linux distribution with python.

2009-05-24 Thread Michael Bernhard Arp Sørensen
Hi there.

I'm on an eternal quest to find the perfect linux distro to base my work on.
I'm currently running Ubuntu because its told that the Ubuntu creator Mark
Shuttleworth is a python hacker. Therefore there's a lot of python stuff in
the repository.

What distro do you run?

Another point: There's so many modules on the Internet, that it's difficult
to get some sort of overview. That's why a distro is such a great idea
because so many packages with python stuff is included. Could you get any
kind of overview over python modules/libs other than a repo in a distro?

I have concluded that there's no such thing as a perfect distro. Only some
distros come close to perfection. In that case I was wondering if I should
create my own python repo to set up a good working environment for
development. That way I could use any distro. On the other hand, any code I
migth write would be difficult for others to use.

Any ideas or comments?

I use emacs with rope, ipython and python. I like those in newer versions if
not bleeding edge.

Med venlig hilsen/Kind regards

Michael B. Arp Sørensen
Programmer / BOFH
Denmark

"If you want to enter my network while I'm out, you can find my SSH-key
under my mouse mat" - Michael Bernhard Arp Sørensen
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] A few very basic questions

2009-05-24 Thread M Tramp

Hello all ...

I've started trying ot learn about Python because I'm intrigued by what I've 
read about Gramps, a genealogical data manager. To run Gramps on a Mac, I need 
to get GTK up and running. Here's where I have a few, hopefully basic, 
questions.

(FYI, I have a Mac, running OS X 10.4.11. Xcode 2.5)

1) GTK has several dependencies, according to 
http://library.gnome.org/devel/gtk-faq/stable/c192.html
... pkg-config; GNU make; JPEG, PNG and TIFF image libraries; FreeType; 
fontconfig; GNU libiconv library; GNU gettext; GLib; Pango; ATK. Each of these 
may have dependencies as well. Is there someplace to go to figure out the order 
they should be compiled? (I started with pkg-config, but it needs GLib) 
Possibly the best answer is to download the source for each and just start 
compiling?

2) Once each library is compiled, what should I have and where should it be on 
my hard drive? For example, when Python sees "import gtk" in which directory is 
it looking for GTK? How will GTK and the other libraries appear on my hard 
disk? As Unix executables or as frameworks or as something else entirely?

3) I am likely to do my Python programming inside Eclipse using pydev, though I 
have Xcode. The libraries will be in C, correct? Will I be able to use Xcode to 
compile GTK and the rest, and then access the libraries inside Eclipse?

mt


  
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] strings using Czech language characters

2009-05-24 Thread Kent Johnson
On Sat, May 23, 2009 at 11:31 PM, Leon Williams  wrote:
> Hello,
>
> I wish to make a dictionary of english to czech words.  I thought I would
> first see if python will print a czech character.  I used the example in the
> tutorial (it uses a euro symbol, and a different iso character set so I
> changed mine to include a character set that includes eastern european
> characters).  My results follow:
>
 # -*- coding: iso_8859-2 -*-
 cz_c = u"č"
> Unsupported characters in input

The coding declaration only affects the encoding of program files, not
the interactive interpreter.

I have some notes here hthat may help:
http://personalpages.tds.net/~kent37/stories/00018.html

Try
  cz_c = "č".decode(sys.stdin.encoding)

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] need help opening a file in idle

2009-05-24 Thread Alan Gauld


"Meital Amitai"  wrote


I am not sure how to open a file in my computer in idle.


You need to be clear what you are doing. You are not
opening the file in IDLE you are opening the file in Python.
IDLE is just the tool you use to write Ptython programs.

For my python class the homework states to write a function that accepts 
the
name of a file and returns a tuple containing the number of lines, words 
and
characters in the file. My problem is how do I get idle to first accept 
the

name of a file.


You need to get Python to accept the name of the file.
And the biggest problem there is to identify the full path
of the file. To program successfully you will need to understand
where and how your computer stores files. On modern computers casual
users don't really need to know that kind of stuff but programmers do.


I created a file in text edit program saved with a .doc
extension, saved on my desktop. However the only way I have learned to 
open

a file in my class is to write something like:

f = open('inputfile','r')
line = f.readline()


but when i type exactly that into my idle i get the following error 
message:

Traceback (most recent call last):
 File "", line 1, in 
   f = open('inputfile','r')
IOError: [Errno 2] No such file or directory: 'inputfile'


I'm assuming you realise that inputfile is a symbol that stands for
any file name it doesn't have to be literally inputfile... But the file
must exist before you can read it (the 'r' bit says you want to
read the file)

and when i ask it to open the actual file i created in my text edit 
program:

file1.doc
f = open('file1.doc','r')
I get the same message.


You didn't tell Python to look in the Desktop folder
(Although that's not a good place to store files unless
you want a very confusing desktop! You would be better
to store it in MyDocuments)

I am not sure how to tell it to go to desktop folder in my computer where 
i

saved that file. Am I missing something, and completely not getting the
point?


It's up to you to know where the file is and tell Python.

You might try this to find out where Python is looking for
the file by default.

import os
print os.getcwd()

Which prints what Python considers the Current Working Directory.

You will find a lot more on this topic, including a program for
counting words in a file in the Handling files topic of my tutorial.

HTH,

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



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor