Hi Folx.
I have a little Problem. I have two Python-Files.
bot.py (for execute)
ascii.py (for data-storage)
The content of ascii.py should be parsed into the bot.py. It should look like the Content of ascii-py is written directly into the bot.py if the bot.py is executed. Tried several Things but no success.
In PHP for example you can include a file "easyli". I need the Pendant for Python. Any Ideas?
Inlcude a .py-File into another .py-File
Page 1 of 17 Replies - 599 Views - Last Post: 02 September 2012 - 06:26 AM
Replies To: Inlcude a .py-File into another .py-File
#2
Re: Inlcude a .py-File into another .py-File
Posted 01 September 2012 - 04:02 AM
#3
Re: Inlcude a .py-File into another .py-File
Posted 01 September 2012 - 04:05 AM
Ok ... here is an example:
bot.py:
Function 1
Function 2
Function 3
ascii.py:
Import 1
Import 2
Import 3
If the bot.py is executed it should look like this for the script:
Function 1
Function 2
Function 3
Import 1
Import 2
Import 3
bot.py:
Function 1
Function 2
Function 3
ascii.py:
Import 1
Import 2
Import 3
If the bot.py is executed it should look like this for the script:
Function 1
Function 2
Function 3
Import 1
Import 2
Import 3
#4
Re: Inlcude a .py-File into another .py-File
Posted 01 September 2012 - 04:11 AM
I do not understand that example. Are "Function i" in your bot.py function definitions? Or function calls? And what are the "Import i" supposed to represent? Import statements?
If you're trying to say that ascii.py contains a bunch of import statements and you want those imported modules to also be available in bot.py (without having to repeat the same import statements in bot.py of course), then that will work fine. Importing a module also imports all modules imported into that module.
If you're trying to say that ascii.py contains a bunch of import statements and you want those imported modules to also be available in bot.py (without having to repeat the same import statements in bot.py of course), then that will work fine. Importing a module also imports all modules imported into that module.
This post has been edited by sepp2k: 01 September 2012 - 04:12 AM
#5
Re: Inlcude a .py-File into another .py-File
Posted 01 September 2012 - 04:23 AM
Ok let me explain with another example:
bot.py
Text 1
Text 4
Text 5
ascii.py
Text 2
Text 3
Should be merged to:
Text 1
Text 4
Text 5
Text 2
Text 3
bot.py
Text 1
Text 4
Text 5
ascii.py
Text 2
Text 3
Should be merged to:
Text 1
Text 4
Text 5
Text 2
Text 3
#6
Re: Inlcude a .py-File into another .py-File
Posted 01 September 2012 - 04:32 AM
Your examples don't really tell me why using import won't work for you.
#7
Re: Inlcude a .py-File into another .py-File
Posted 02 September 2012 - 04:14 AM
Those examples don't even make sense, really. Could you be more specific in what you're trying to do and what isn't working?
EDIT:
It sounds like he wants the code in the module to execute by virtue of importing it rather than explicitly calling functions within it...
EDIT:
It sounds like he wants the code in the module to execute by virtue of importing it rather than explicitly calling functions within it...
This post has been edited by atraub: 02 September 2012 - 06:25 AM
#8
Re: Inlcude a .py-File into another .py-File
Posted 02 September 2012 - 06:26 AM
I am not sure what you mean with your examples, but from what I can gather, you want to run bot.py and use the functions of ascii.py in it? If that is right, then importing it should work fine (as sepp2k mentioned), by doing something like this:
and in your ascii, you should have something like
That should work? The include that you are talking about in PHP, doesn't really need to be used in python because of the way the module systems work. When you run your code and you make a call to an imported function, it is like the code is where you made the call, but really it is just in the memory with the other code. I think you may have been misunderstanding how this worked.
Otherwise, it may just be easier to put the code into the bot.py file as a function or where you need it?
I hope this is what you wanted.
#this is the bot.py import ascii #~Code in bot.py ~ print text1 print ascii.process(text2) print text3 #etc.
and in your ascii, you should have something like
def process(text):
text += '-Extra'
return text
That should work? The include that you are talking about in PHP, doesn't really need to be used in python because of the way the module systems work. When you run your code and you make a call to an imported function, it is like the code is where you made the call, but really it is just in the memory with the other code. I think you may have been misunderstanding how this worked.
Otherwise, it may just be easier to put the code into the bot.py file as a function or where you need it?
I hope this is what you wanted.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote







|