6 Replies - 1498 Views - Last Post: 23 August 2011 - 12:49 AM Rate Topic: -----

#1 cupidvogel   User is offline

  • D.I.C Addict

Reputation: 31
  • View blog
  • Posts: 593
  • Joined: 25-November 10

List of modules

Posted 21 August 2011 - 11:15 PM

Can anyone tell me how do I view which modules are already imported in my Python directory? For example, I want to see a list where the modules are named serially, like CMATH, STRING, SYS, etc. I read somewhere that I should use import SYS, then execute the command sys.path, which will give me the location of the modules. I did so, and I got this:

['C:\\Python27\\Lib\\idlelib', 'C:\\windows\\system32\\python27.zip', 'C:\\Python27\\DLLs', 'C:\\Python27\\lib', 'C:\\Python27\\lib\\plat-win', 'C:\\Python27\\lib\\lib-tk', 'C:\\Python27', 'C:\\Python27\\lib\\site-packages']



There are a number of paths in this list, all pointing to different locations. One or two I couldn't even find. The ones I could, I searched for modules there, and I couldn't find most. For example, in the folder specified by the first path in the list, I found lots of files with .py and .pyc extensions, but I found neither CMATH, nor STRING modules. Where can I find them, and how? Will they be .py files, or .pyc files? And what's the difference between .py and .pyc files?

Is This A Good Question/Topic? 0
  • +

Replies To: List of modules

#2 chemicalfan   User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 95
  • Joined: 16-October 09

Re: List of modules

Posted 22 August 2011 - 05:31 AM

They'll be pyc files, but there will be loads of them. How come you need this information? I don't think an actual log of imported modules is kept anywhere, you'd have to build one by somehow analysing the pyc files (even that's not a guarentee of a module, as any Python code (py files) will get compiled to pyc on execute
Was This Post Helpful? 0
  • +
  • -

#3 Motoma   User is offline

  • D.I.C Addict
  • member icon

Reputation: 452
  • View blog
  • Posts: 798
  • Joined: 08-June 10

Re: List of modules

Posted 22 August 2011 - 06:48 AM

You will in fact have to look through all of these folders, as Python will look in each one until it finds the module it's looking for.

You will want to look for .py files as well as sub-folders, as those will be the two things you import. .pyc files are byte-code compiled versions of these.
Was This Post Helpful? 0
  • +
  • -

#4 chemicalfan   User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 95
  • Joined: 16-October 09

Re: List of modules

Posted 22 August 2011 - 07:41 AM

Isn't it true, that the first time a .py module is imported, it's compiled into .pyc?
Was This Post Helpful? 0
  • +
  • -

#5 Motoma   User is offline

  • D.I.C Addict
  • member icon

Reputation: 452
  • View blog
  • Posts: 798
  • Joined: 08-June 10

Re: List of modules

Posted 22 August 2011 - 08:09 AM

View Postchemicalfan, on 22 August 2011 - 10:41 AM, said:

Isn't it true, that the first time a .py module is imported, it's compiled into .pyc?

Yes, and at install time you have the option to pre-compile the standard modules, however, you can't guarantee every single module has been compiled.
Was This Post Helpful? 0
  • +
  • -

#6 cupidvogel   User is offline

  • D.I.C Addict

Reputation: 31
  • View blog
  • Posts: 593
  • Joined: 25-November 10

Re: List of modules

Posted 22 August 2011 - 09:28 AM

View Postchemicalfan, on 22 August 2011 - 12:31 PM, said:

They'll be pyc files, but there will be loads of them. How come you need this information? I don't think an actual log of imported modules is kept anywhere, you'd have to build one by somehow analysing the pyc files (even that's not a guarentee of a module, as any Python code (py files) will get compiled to pyc on execute

Actually i wanted to know where are the modules imported from when I use import modules. Felt strange that I am importing modules without knowing where they are, or in fact, whether they are there in the first place.
Was This Post Helpful? 0
  • +
  • -

#7 chemicalfan   User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 95
  • Joined: 16-October 09

Re: List of modules

Posted 23 August 2011 - 12:49 AM

Check this out - http://docs.python.o...ule-search-path
;)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1