Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between a "source folder" and a "pydev package" in PyDev Eclipse?

What is the difference between a "source folder" and a "pydev package" in PyDev Eclipse?

Menu options for creating new item in PyDev

like image 673
alwbtc Avatar asked Aug 31 '13 09:08

alwbtc


People also ask

How to remove PyDev from Eclipse?

To uninstall you should either go on and remove the org. python. pydev* from eclipse/plugins and eclipse/features or you can go to help > software updates > manage configuration, choose the PyDev plugin and disable it (after that, to completely remove it, you must restart Eclipse and only then select it for uninstall).

How do I open PyDev Package Explorer?

To switch to PyDev, if it isn't already selected, choose Window > Perspective > Open Perspective > Other > PyDev. Then, select the PyDev Package Explorer view by choosing Window > Show View > PyDev Package Explorer to see and access the contents of each project directory.

How do I open PyDev project in Eclipse?

Go to Window → Open Perspective → Other and choose PyDev, then click OK. If you look at the upper right corner you will see that the perspective has changed from "Java" to "PyDev".


3 Answers

a package is a collector for files that have a logical grouping

import <package>.<file>

and a source folder makes the files directly importable

import <file>

and the regular folder is basically inaccessible.

I made a quick project that shows the differences. I put one file in each type of container: regular folder, package, and source folder. Each file had two items: a function called show() and a class with a single public member show()

enter image description here

I then put a driver file at the top level (in the project root, next to the 3 containers). This was just to try the different ways of importing things. Here is a copy of that driver file with comments to describe how the different elements are used:

### valid imports
import package
import package.file_in_package as thefileinpackage
import file_in_source

### invalid imports
#import package.file_in_package.packageclass   #runtime ImportError
#import file_in_package                        #unresolved import

#import source                                 #unresolved import
#import source.file_in_source                  #unresolved import
#import file_in_source.sourceclass             #runtime ImportError

#import folder                                 #unresolved import
#import file_in_folder                         #unresolved import
#import folder.file_in_folder                  #unresolved import

thefileinpackage.show()
packageclasss_inst = thefileinpackage.packageclass()
packageclasss_inst.show()

file_in_source.show()
sourceclass_inst = file_in_source.sourceclass()
sourceclass_inst.show()

package.file_in_package.show()
packageclass_inst2 = package.file_in_package.packageclass()
packageclass_inst2.show()
like image 141
anregen Avatar answered Oct 25 '22 02:10

anregen


A "source folder" is a directory that contains source files. Putting .py files into this directory will make them discoverable by PyDev, so that you can for instance import them from other Python files.

A "PyDev Package" is a Python package. This means that it contains a file called __init__.py. For example, if you create a new PyDev Package with name foo, then you will get file foo/__init__.py. You can place other .py files into foo/, which you can then import. So, if you place bar.py into foo/, then you can do

import foo.bar

This is not possible with source folders.

You normally place packages into source folders. I don't know if it is possible to place a source folder into a package, but even if it were you would hardly ever do it.

like image 40
Michael Herrmann Avatar answered Oct 25 '22 03:10

Michael Herrmann


A source folder is the folder which is added to the PYTHONPATH.

A package is a folder which has an __init__.py file (and which is located beneath a source folder).

like image 26
Fabio Zadrozny Avatar answered Oct 25 '22 03:10

Fabio Zadrozny