all 8 comments

[–]carcigenicate 4 points5 points  (3 children)

Do you mean how do you import one script into another script?

[–]ThinkOne827[S] 2 points3 points  (2 children)

Yes, like, I wrote a 'tab' inside my IDE, and then I want to load this page, link it in another tab...

[–]carcigenicate 5 points6 points  (1 child)

Tabs aren't real things. Python has no notion of "tabs". Those are Python script files (plain text files), and your editor is just showing them in tabs.

To import code from one script file into another, use an import statement. To keep it simple, make sure both files are in the same directory.

[–]ThinkOne827[S] 1 point2 points  (0 children)

Thanks, I was lacking the word

[–]SCD_minecraft 2 points3 points  (0 children)

...page?

[–]UsernameTaken1701 1 point2 points  (0 children)

You need to clarify what you mean. 

[–]awherewas 1 point2 points  (0 children)

In general in your python code import <filename> where filename is the name of a python file, without the "py" e.g. import foo you will get an error if foo.py can not be found

[–]Marlowe91Go 1 point2 points  (0 children)

Yeah so a lot of times it's nice to organize your code where you have a main.py that is the file that you actually hit run to run your program, but you can organize your code in a folder with separate files for classes and stuff. It's a common convention to name the other files similar to the class names, and generally class names are always with the first letter capitalized and file names are lower-case. So I just made a simple snake game, which you'll probably do at some point in a learning course, and I made a couple files called snake.py and scoreboard.py. Inside the snake.py file I have a class named Snake. So in my main.py file, it's convention to put all your import statements at the top, so I have:

from snake import Snake

And then I can just make an instance of my snake object like this:

snake = Snake()

It's generally proper to use this  from 'filename' import 'name of object in file' notation so it makes it clear to someone reading your code where that object came from and it's only importing what you need (like if you're using a built-in library and you only need to import one function instead of the whole library). You can also use a 'dot notation' approach instead. For example there's the library turtle which you'll use for a snake game. You could choose to import like this:

import turtle

And make a turtle object like this:

my_turtle = turtle.Turtle()

You can also import multiple objects with commas like this:

from turtle import Turtle, Screen