Hi guys!
I start using Python few days ago, for a game server ( it'a an online game ). I made a server for that game, I start it on my pc, and for do this I need to start Server.py too, or, it wouldn't connect to the server.
I host the server filles on a Python host, how i can start the Server.py using a command in Python's console? ( on the host site )
I have the Server.py fille, on / > home >  elyos > transformice > Server.py

I start a new Python console ( is the version important?
Python: 2.7 / 2.6 / 3.2  ? )
and then what I write to start the Server.py file?

Recommended Answers

All 8 Replies

First off, it isn't in most cases necessary to enter into the Python console itself to run a file; you can instead just open a system console window and use

python Server.py

and the program should run. For that matter, if you are running Windows, the file assocations should automagically run the Python interpreter for you if you double-click on the Server.py file. Under most Unices, such as Linux or MacOS X, you can add a shebang line at the beginning of the file to invoke the interpreter:

#!/usr/bin/python 

Now, if you'd still prefer to run the program from the Python console, then you will want to use an import statement:

from Server import *

or just

import Server

However, this requires that you invoke the console in the same directory as the Server.py file.

As for the issue of version, yes, the version matters greatly, at least with regards to the 2.x versions versus the 3.x versions. The language has been substantially overhauled in version 3, in ways that broke a lot of programs written for version 2; this is why the two different versions have continued to be maintained. If your program was written for version 2.x, then chances are it won't run under 3.x, but many 3.x programs wil run under 2.6 or 2.7 (but not generally earlier than that). It all depends on the version that Server.py was written for. If you are still writing Server.py, then it is strongly recommended to use version 3.x, as there are significant improvements that you can take advantage of if you do.

It runs on linux2, and I want to run non-stop ( i mean 24/24 ) that Server.py, 'cause i want my server to be non-stop online

it doesn't work

>>> python Server.py                                                                                                                                                   
  File "<stdin>", line 1                                                                                                                                               
    python Server.py                                                                                                                                                   
                ^                                                                                                                                                      
SyntaxError: invalid syntax                                                                                                                                            
>>>   

it's not a pc!!!
it's https://www.pythonanywhere.com

It wont work like that. Exit the Python console and then type
`python Server.py'

You can't run a script from within the interpreter.

Or you must open the script and run it in Ui of pythonanywhere.

I am fairly sure that the from Server import * should work, assuming that you are running in your working directory (which ought to be the case, as you probably only get access to your own folder on their server). Not having worked with PythonAnywhere, I cannot say for certain. I would say pyTony's suggestion of using the PythonAnywhere user interface is the best approach overall.

I do not see why you posted those pictures. Your web wcgi application should be setup in web tab preferably using django or web2py, like it clearly says in picture you linked to.

yea.. but i'm newbie, can u give me some more details? a step by step tut. would be great.. x-x

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.