Source code for itertools

V

vsoler

I'm interested in studying the itertools source code, especially the
permutations function.

However, I cannot find the library. Where could I find it?

Running Python 3.1

Thank you
 
L

Lawrence D'Oliveiro

I'm interested in studying the itertools source code, especially the
permutations function.

However, I cannot find the library. Where could I find it?

ldo@theon:python> apt-get source python3.1
Reading package lists... Done
Building dependency tree
Reading state information... Done
Need to get 12.0MB of source archives.
Get:1 http://ftp.nz.debian.org sid/main python3.1 3.1.2+20100829-1 (dsc) [1,776B]
Get:2 http://ftp.nz.debian.org sid/main python3.1 3.1.2+20100829-1 (tar) [11.8MB]
Get:3 http://ftp.nz.debian.org sid/main python3.1 3.1.2+20100829-1 (diff) [239kB]
Fetched 12.0MB in 28s (417kB/s)
dpkg-source: info: extracting python3.1 in python3.1-3.1.2+20100829
dpkg-source: info: unpacking python3.1_3.1.2+20100829.orig.tar.gz
dpkg-source: info: applying python3.1_3.1.2+20100829-1.diff.gz
ldo@theon:python> find . -iname \*itertools\*
../python3.1-3.1.2+20100829/Modules/itertoolsmodule.c
../python3.1-3.1.2+20100829/Lib/test/test_itertools.py
../python3.1-3.1.2+20100829/Lib/lib2to3/fixes/fix_itertools_imports.py
../python3.1-3.1.2+20100829/Lib/lib2to3/fixes/fix_itertools.py
../python3.1-3.1.2+20100829/Doc/library/itertools.rst
 
V

vsoler

I'm interested in studying the itertools source code, especially the
permutations function.
However, I cannot find the library. Where could I find it?

ldo@theon:python> apt-get source python3.1
Reading package lists... Done
Building dependency tree      
Reading state information... Done
Need to get 12.0MB of source archives.
Get:1http://ftp.nz.debian.orgsid/main python3.1 3.1.2+20100829-1 (dsc) [1,776B]
Get:2http://ftp.nz.debian.orgsid/main python3.1 3.1.2+20100829-1 (tar) [11.8MB]
Get:3http://ftp.nz.debian.orgsid/main python3.1 3.1.2+20100829-1 (diff) [239kB]                  
Fetched 12.0MB in 28s (417kB/s)                                                                    
dpkg-source: info: extracting python3.1 in python3.1-3.1.2+20100829
dpkg-source: info: unpacking python3.1_3.1.2+20100829.orig.tar.gz
dpkg-source: info: applying python3.1_3.1.2+20100829-1.diff.gz
ldo@theon:python> find . -iname \*itertools\*
./python3.1-3.1.2+20100829/Modules/itertoolsmodule.c
./python3.1-3.1.2+20100829/Lib/test/test_itertools.py
./python3.1-3.1.2+20100829/Lib/lib2to3/fixes/fix_itertools_imports.py
./python3.1-3.1.2+20100829/Lib/lib2to3/fixes/fix_itertools.py
./python3.1-3.1.2+20100829/Doc/library/itertools.rst


I was expecting an itertools.py file, but I don't see it in your list.

I can instead see the test_itertools.py file, but my understanding is
that it is not the file I am looking for.

Is it possible that it is a built-in module whose source code is not
available for watching it?

Thank you very much
 
P

Paul Rubin

vsoler said:
I was expecting an itertools.py file, but I don't see it in your list.

looks promising. Lots of stdlib modules are written in C for speed or
access to system facilities.
 
V

vsoler

looks promising.  Lots of stdlib modules are written in C for speed or
access to system facilities.

Lawrence, Paul,

You seem to be running a utility I am not familiar with. Perhaps this
is because I am using Windows, and most likely you are not.

How could I have found the answer in a windows environment?

Thank you very much
 
R

Rolando Espinoza La Fuente

Lawrence, Paul,

You seem to be running a utility I am not familiar with. Perhaps this
is because I am using Windows, and most likely you are not.

How could I have found the answer in a windows environment?

Hard question. They are using standard unix utilities.

But you can find the source file of a python module within python:
/usr/lib/python2.6/lib-dynload/itertools.so

Yours should point to a windows path. If the file ends with a ".py",
you can open the file
with any editor. If ends with ".so" or something else likely is a
compiled module in C
and you should search in the source distribution, not the binary distribution.

Hope it helps.

Regards,


Rolando Espinoza La fuente
www.insophia.com
 
T

Terry Reedy

I was expecting an itertools.py file, but I don't see it in your
list.

The manual page has the original python source for each function.
I recommend you look at that.
Itertool was rewritten in C for speed but the C source will not tell you
any more about the functions themselves.
 
V

vsoler

Hard question. They are using standard unix utilities.

But you can find the source file of a python module within python:


/usr/lib/python2.6/lib-dynload/itertools.so

Yours should point to a windows path. If the file ends with a ".py",
you can open the file
with any editor. If ends with ".so" or something else  likely is a
compiled module in C
and you should search in the source distribution, not the binary distribution.

Hope it helps.

Regards,

Rolando Espinoza La fuentewww.insophia.com

Thank you Rolando for your contribution.

Followinf your piece of advice I got:
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
print(itertools.__file__)
AttributeError: 'module' object has no attribute '__file__'
So, I undestand that the module is written in C.

Vicente Soler
 
V

vsoler

Did you take the time to understand what he did?  It's not that hard to
figure out.  He fetched the Python source code, unpacked it, then search
for filenames that contained the string "itertools."

The equivalent in Windows, after unpacking the source archive, would have
been:
    dir /s *itertools*

Thank you Tim, understood!!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,169
Messages
2,570,920
Members
47,464
Latest member
Bobbylenly

Latest Threads

Top