[Tutor] Making a simple web server in Python

2011-05-30 Thread Michael bridges
when running code from http://fragments.turtlemeat.com/pythonwebserver.php: 
[putting http://localhost:81/index.html in broswer]
this error happens:
>>> 
Traceback (most recent call last):
  File 
"C:\Users\MySelf\Program\game_stuff\Python_Server_code_and_test\pythonweb\webserver.py",
 line 65, in 
main()
  File 
"C:\Users\MySelf\Program\game_stuff\Python_Server_code_and_test\pythonweb\webserver.py",
 line 56, in main
server = HTTPServer(('', 80), MyHandler)
  File "C:\Python31\lib\socketserver.py", line 400, in __init__
self.server_bind()
  File "C:\Python31\lib\http\server.py", line 127, in server_bind
socketserver.TCPServer.server_bind(self)
  File "C:\Python31\lib\socketserver.py", line 411, in server_bind
self.socket.bind(self.server_address)
socket.error: [Errno 10013] An attempt was made to access a socket in a way 
forbidden by its access permissions
>>> 


[with port 80 changed to port 81, can not use port 80 for some reason]
this error happens:
>>> 
started httpserver...
michaeleric-PC - - [30/May/2011 15:00:24] "GET /index.html HTTP/1.1" 200 -

Exception happened during processing of request from ('127.0.0.1', 62592)
Traceback (most recent call last):
  File "C:\Python31\lib\socketserver.py", line 281, in _handle_request_noblock
self.process_request(request, client_address)
  File "C:\Python31\lib\socketserver.py", line 307, in process_request
self.finish_request(request, client_address)
  File "C:\Python31\lib\socketserver.py", line 320, in finish_request
self.RequestHandlerClass(request, client_address, self)
  File "C:\Python31\lib\socketserver.py", line 614, in __init__
self.handle()
  File "C:\Python31\lib\http\server.py", line 352, in handle
self.handle_one_request()
  File "C:\Python31\lib\http\server.py", line 346, in handle_one_request
method()
  File 
"C:\Users\MySelf\Program\game_stuff\Python_Server_code_and_test\pythonweb\webserver.py",
 line 20, in do_GET
self.wfile.write(f.read())
  File "C:\Python31\lib\socket.py", line 219, in write
return self._sock.send(b)
TypeError: must be bytes or buffer, not str

^C received, shutting down server
>>> 

changing to port 29876 gives same error & did not want to stop, kept restarting.

[putting http://localhost/index.html in broswer]
gives 404 error

[putting http://localhost/index.esp in broswer]
gives 404 error

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] No module named player_data

2011-06-05 Thread Michael bridges
why does this happen?

server [folder]
   player_data [folder]
   server.py

Traceback (most recent call last):
  File 
"C:\Users\MySelf\Program\game_stuff\Game_28_02_11\Servers\server_client_begining\server.py",
 line 3, in 
from player_data import PlayerArmy
ImportError: No module named player_data


from player_data import PlayerArmy
from player_data import PlayerBaseData
from player_data import PlayerEnabledFlags
from player_data import PlayerResearch
from player_data import PlayerResearchers
from player_data import PlayerTotalWeapons
from player_data import PlayerWeaponsEquipped
from player_data import PlayerWeaponsUnequipped

this worked before i tried:
from player_data import *
"""from player_data import PlayerArmy
from player_data import PlayerBaseData
from player_data import PlayerEnabledFlags
from player_data import PlayerResearch
from player_data import PlayerResearchers
from player_data import PlayerTotalWeapons
from player_data import PlayerWeaponsEquipped
from player_data import PlayerWeaponsUnequipped"""

got error about PlayerBaseData not found

then undid back to:
from player_data import PlayerArmy
from player_data import PlayerBaseData
from player_data import PlayerEnabledFlags
from player_data import PlayerResearch
from player_data import PlayerResearchers
from player_data import PlayerTotalWeapons
from player_data import PlayerWeaponsEquipped
from player_data import PlayerWeaponsUnequipped

now it does not work
why
using python 3 and tried with python 2.7
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] No module named player_data

2011-06-05 Thread Michael bridges
one of the things i deleted was __init__.py & __init__.pyc [thought it was not 
used, then read import again and put it back. still not working]

player_data [folder]
   __init__.py
   [several .py & .pyc files]


--- On Sun, 6/5/11, Alexandre Conrad  wrote:

> From: Alexandre Conrad 
> Subject: Re: [Tutor] No module named player_data
> To: "Michael bridges" 
> Cc: Tutor@python.org
> Date: Sunday, June 5, 2011, 7:11 PM
> 2011/6/5 Michael bridges :
> > why does this happen?
> >
> > server [folder]
> >       player_data [folder]
> >       server.py
> >
> > Traceback (most recent call last):
> >  File
> "C:\Users\MySelf\Program\game_stuff\Game_28_02_11\Servers\server_client_begining\server.py",
> line 3, in 
> >    from player_data import PlayerArmy
> > ImportError: No module named player_data
> 
> If player_data is a package (a folder containing an
> __init__.py file),
> I guess you have your class PlayerArmy defined inside the
> __init__.py
> file, or you are importing PlayerArmy from __init__.py.
> 
> Could you provide more details on what the "player_data"
> folder contains?
> 
> -- 
> Alex | twitter.com/alexconrad
> 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] No module named player_data

2011-06-05 Thread Michael bridges
more specific general info [do not want to copy/paste the whole files]:

[\server_client_begining\server.py]
from player_data import PlayerArmy


[\server_client_begining\player_data\PlayerArmy]
#PlayerArmy
playerName = "john"
militia_amount = 100
military_amount = 10
[with more variables]
[no classes, no functions, just variables]

--- On Sun, 6/5/11, Alexandre Conrad  wrote:

> From: Alexandre Conrad 
> Subject: Re: [Tutor] No module named player_data
> To: "Michael bridges" 
> Cc: Tutor@python.org
> Date: Sunday, June 5, 2011, 7:11 PM
> 2011/6/5 Michael bridges :
> > why does this happen?
> >
> > server [folder]
> >       player_data [folder]
> >       server.py
> >
> > Traceback (most recent call last):
> >  File
> "C:\Users\MySelf\Program\game_stuff\Game_28_02_11\Servers\server_client_begining\server.py",
> line 3, in 
> >    from player_data import PlayerArmy
> > ImportError: No module named player_data
> 
> If player_data is a package (a folder containing an
> __init__.py file),
> I guess you have your class PlayerArmy defined inside the
> __init__.py
> file, or you are importing PlayerArmy from __init__.py.
> 
> Could you provide more details on what the "player_data"
> folder contains?
> 
> -- 
> Alex | twitter.com/alexconrad
> 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] No module named player_data

2011-06-05 Thread Michael bridges
Traceback (most recent call last):
  File 
"C:\Users\MySelf\Program\game_stuff\Game_28_02_11\Servers\server_client_begining\server.py",
 line 3, in 
from player_data import PlayerArmy
ImportError: No module named player_data


--- On Sun, 6/5/11, Alexandre Conrad  wrote:

> From: Alexandre Conrad 
> Subject: Re: [Tutor] No module named player_data
> To: "Michael bridges" 
> Cc: Tutor@python.org
> Date: Sunday, June 5, 2011, 7:58 PM
> 2011/6/5 Michael bridges :
> > one of the things i deleted was __init__.py &
> __init__.pyc [thought it was not used, then read import
> again and put it back. still not working]
> 
> You always need an __init__.py file in a folder that you
> want to
> import in Python. That tells Python to consider the folder
> as a Pyton
> package.
> 
> http://effbot.org/pyfaq/what-is-init-py-used-for.htm
> 
> Your original error was: "ImportError: No module named
> player_data".
> Now you have the file back, I now suspect the error message
> might be
> slightly different. Could you copy/paste it please?
> 
> 
> -- 
> Alex | twitter.com/alexconrad
> 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] No module named player_data

2011-06-05 Thread Michael bridges
simple
file was named __ init __.py not __init__.py
restored from recycle bin showed the error

thanks for your help


--- On Sun, 6/5/11, Alexandre Conrad  wrote:

> From: Alexandre Conrad 
> Subject: Re: [Tutor] No module named player_data
> To: "Michael bridges" 
> Cc: Tutor@python.org
> Date: Sunday, June 5, 2011, 7:58 PM
> 2011/6/5 Michael bridges :
> > one of the things i deleted was __init__.py &
> __init__.pyc [thought it was not used, then read import
> again and put it back. still not working]
> 
> You always need an __init__.py file in a folder that you
> want to
> import in Python. That tells Python to consider the folder
> as a Pyton
> package.
> 
> http://effbot.org/pyfaq/what-is-init-py-used-for.htm
> 
> Your original error was: "ImportError: No module named
> player_data".
> Now you have the file back, I now suspect the error message
> might be
> slightly different. Could you copy/paste it please?
> 
> 
> -- 
> Alex | twitter.com/alexconrad
> 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] floats

2011-06-06 Thread Michael bridges
i saw it somewhere, but where?

i want to 10 / 1000 and get 0.01 not 0
if 1000 is made 1000.00 then 0.01 is printed
but that gives 500 / 1000.00 is 0.5 not 0.50

i might be thinking C# not python.

can someone till me how to get a two decimal precision every time?

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] floats

2011-06-07 Thread Michael bridges
ok, will attempt to clarify.
i want to out put of two numbers [int or float or anything] to be x.xx not x.x.
i want two numbers after the decimal not one.


--- On Tue, 6/7/11, Alan Gauld  wrote:

> From: Alan Gauld 
> Subject: Re: [Tutor] floats
> To: tutor@python.org
> Date: Tuesday, June 7, 2011, 1:16 AM
> 
> "Michael bridges" 
> wrote
> 
> > i want to 10 / 1000 and get 0.01 not 0
> > if 1000 is made 1000.00 then 0.01 is printed
> > but that gives 500 / 1000.00 is 0.5 not 0.50
> > 
> > can someone till me how to get a two decimal precision
> every time?
> 
> You are confusing two different things..
> The first case is that of integer versus float division.
> You solve that by either explicitly making one of the
> numbers a float or by converting to float using the
> foloat() operation.
> 
> The second issue is the *representation* of the result.
> The number of decimal places displayed is a matter
> of representation only, the actual value stored will not
> change. Thus 0.5 and 0.50 and 0.5000 are all
> the same value in memory, it is only how they are
> printed that changes and that is controlled by how
> you choose to format the display.
> 
> Typically you use a format string:
> 
> res = 10/float(20)
> "%f" % res
> "%7.3f" % res
> "%5.1f" % res
> "%6e" % res
> "%6.4g" % res
> 
> 
> HTH,
> 
> -- Alan Gauld
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> 
> 
> 
> 
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
> 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] using python to write web page

2011-06-15 Thread Michael bridges
i would like to use python to write a web page like writing an html file that 
is displayed in a browser without having to run a server.

found a few options, but need to have server running.

https://skulpt.googlecode.com/hg/skulpt
gives 404 error



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor