Newbie - instanciating classes from other files

C

comanighttrain

Hey guys, i just started learning python (i usually use java/C).

this has got me stumped as its not mentioned in the documentation
(unless im skimming it every time).

How does one instanciate a class from another file

i thought it would be
-----------------------------------code---------------------------
import file.py

thisFile = ClassName()
-------------------------------not code---------------------------
but its not

and its not
-----------------------------------code---------------------------
thisFile= filename.ClassName()
-------------------------------not code---------------------------
im stuck:(

cheers
dave
 
J

Jorge Godoy

Hey guys, i just started learning python (i usually use java/C).

this has got me stumped as its not mentioned in the documentation
(unless im skimming it every time).

How does one instanciate a class from another file

i thought it would be
-----------------------------------code---------------------------
import file.py

thisFile = ClassName()
-------------------------------not code---------------------------

import file # see that there's no ".py"
thisFile = file.ClassName()

or


from file import ClassName
thisFile = ClassName()


This is in the docs.
 
D

Devan L

Hey guys, i just started learning python (i usually use java/C).

this has got me stumped as its not mentioned in the documentation
(unless im skimming it every time).

How does one instanciate a class from another file

import somefile
foo = somefile.class(__init__arguments-should-go-here)

Don't include the .py, it's won't work.
 
P

Peter Hansen

Hey guys, i just started learning python (i usually use java/C).

this has got me stumped as its not mentioned in the documentation
(unless im skimming it every time).

How does one instanciate a class from another file

i thought it would be
-----------------------------------code---------------------------
import file.py

thisFile = ClassName()
-------------------------------not code---------------------------

It's clear you haven't worked through the tutorial. It's short, easy,
and educational, so why not save yourself from embarrassment and whip
through it rather than trying to learn Python by guess-and-error?

-Peter
 

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

No members online now.

Forum statistics

Threads
474,264
Messages
2,571,317
Members
48,003
Latest member
coldDuece

Latest Threads

Top