Re: [Tutor] Python with HTML
> hi everyone, > > I want to make a web page which has to include some python script and html > tags as well, am not getting how to do that . > I searched some articles but cant understand them . > is there anything like linking an external html file into python script ? > > Can u please help for same > waiting for your instructions or some links that can help me Not sure what you want. Do you want a HTML page that includes a Python script for the more dynamic parts? In that case: that won't work. Java (ecma)script is the de facto standard for this. You can try and compile Python to javascript using eg Pyjamas (http://pyjs.org/). If you want your Python script to generate HTML, you can just write out the necessary code using print statements or to a file. Which articles did you search for, and what did you not understand? Evert ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python with HTML
If you're hoping for something like PHP that can be parsed inline with html, you're out of luck. It's also bad design to mix business logic with your presentation layer. You might want to look into some frameworks like django to help you along. On Jan 28, 2012 2:04 AM, "t4 techno" wrote: > hi everyone, > > I want to make a web page which has to include some python script and html > tags as well, am not getting how to do that . > I searched some articles but cant understand them . > is there anything like linking an external html file into python script ? > > Can u please help for same > waiting for your instructions or some links that can help me > > Regards > > ___ > 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
Re: [Tutor] Python with HTML
Evert Rol wrote: hi everyone, I want to make a web page which has to include some python script and html tags as well, am not getting how to do that . I searched some articles but cant understand them . is there anything like linking an external html file into python script ? Can u please help for same waiting for your instructions or some links that can help me Not sure what you want. Do you want a HTML page that includes a Python script for the more dynamic parts? In that case: that won't work. Java (ecma)script is the de facto standard for this. While Javascript is the de facto standard for client-side scripting, it is possible to use Python. But you shouldn't: Python is not designed with the sort of sand-boxing and security needed to run untrusted code over the Internet. But if you only care about running code within your own trusted intranet, it should be perfectly doable. http://bytes.com/topic/python/answers/45528-python-client-side-browser-script-language A better idea may be to use a templating engine, server-side Python, e.g. using Django, CherryPy, or similar, or use Pyjamas to convert Python to Javascript. http://warp.byu.edu/site/content/813 -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python with HTML
> > I want to make a web page which has to include some python script and html >> tags as well, am not getting how to do that . >> > ** Hi, Maybe a quick and small solution is here : http://karrigell.sourceforge.net/en/index.html It doesn't seem to be a very living project, but it can be a solution for you, depending of what you want. There is also python integration in Apache : http://www.modpython.org/ And finaly a more more (maybe too much) powerfull solution is maybe Zope : http://www.zope.org/ Regards, Patrice ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python with HTML
t4 techno, 28.01.2012 11:02: > I want to make a web page which has to include some python script and html > tags as well, am not getting how to do that . > I searched some articles but cant understand them . > is there anything like linking an external html file into python script ? > > Can u please help for same > waiting for your instructions or some links that can help me As others have pointed out, your request is not very clear. I agree that client side Python in a browser is not the best approach, but if your question is about server side HTML generation from Python, you should either look at one of the web frameworks (a couple of them were already mentioned), or use a templating engine. There are plenty of them for Python, here is a list: http://wiki.python.org/moin/Templating There are also plenty of web frameworks, BTW. They are better than plain templating engines when your data becomes non-trivial and comes from a database etc. Depending on what you actually want to do (note that you only said *how* you want to do it, not *what* you want to do), you should also look at content management systems like Plone. Hope that helps, Stefan ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Deleting an object
Hi all, Last time I tried to post a question regarding this, I was asked to clarify. Okay so here it is. There is a class called Table and objects are just tables, you know, matrices, holding different types of data. Thing is, I want to provide a method where one can delete the object and then if the user tries using a variable to access a certain method or attributes, he gets an error. Let me give an example; class Table: def delete_this(self): #code to delete this object or assign it null or None pass def do_something(self): pass x=Table() x.delete_this() #at this point, I want such that if I try to use x I get some sort of error e.g. x.do_something() #Error: x is definitely not an object anymore All clear? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Deleting an object
On Sun, Jan 29, 2012 at 4:14 PM, George Nyoro wrote: > Hi all, > > Last time I tried to post a question regarding this, I was asked to > clarify. Okay so here it is. There is a class called Table and objects are > just tables, you know, matrices, holding different types of data. Thing is, > I want to provide a method where one can delete the object and then if the > user tries using a variable to access a certain method or attributes, he > gets an error. Let me give an example; > > class Table: > > def delete_this(self): > > #code to delete this object or assign it null or None > > pass > > def do_something(self): > > pass > > x=Table() > > x.delete_this() > > #at this point, I want such that if I try to use x I get some sort of error > e.g. > > x.do_something() > > #Error: x is definitely not an object anymore > > > All clear? > __getattribute__ is the closest you'll get to that, e.g. like the class below. A complete implementation is impossible, since language builtins bypass even the __getattribute__ method, but as long as you do not use them you should be fine: class Table(object): def __init__(self): self.deleted = False def __getattribute__(self, attr): if object.__getattribute__(self, 'deleted'): raise AttributeError("this object has been deleted") return object.__getattribute__(self, attr) def __len__(self): return 10 def delete(self): self.deleted = True >>> # the object is still alive, we can access stuff easily >>> t = Table() >>> t.deleted False >>> t.__len__() 10 >>> t.delete() >>> # now we cant access anything anymore without raising an error >>> t.deleted Traceback (most recent call last): File "", line 1, in t.deleted File "C:\Users\hugo\Downloads\test.py", line 7, in __getattribute__ raise AttributeError("this object has been deleted") AttributeError: this object has been deleted >>> t.__len__() Traceback (most recent call last): File "", line 1, in t.__len__() File "C:\Users\hugo\Downloads\test.py", line 7, in __getattribute__ raise AttributeError("this object has been deleted") AttributeError: this object has been deleted >>> # unfortunately, the python internals can still access your methods, so >>> len() and things like operators will still work. There is no way around this >>> len(t) 10 >>> Of course this method can easily be adapted to restrict access only to certain methods/attributes. HTH, Hugo ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Deleting an object
On Sun, Jan 29, 2012 at 10:14 AM, George Nyoro wrote: > Hi all, > Last time I tried to post a question regarding this, I was asked to > clarify. Okay so here it is. There is a class called Table and objects are > just tables, you know, matrices, holding different types of data. Thing is, > I want to provide a method where one can delete the object and then if the > user tries using a variable to access a certain method or attributes, he > gets an error. Let me give an example; > > class Table: > > def delete_this(self): > > #code to delete this object or assign it null or None > > pass > > def do_something(self): > > pass > > x=Table() > > x.delete_this() > > #at this point, I want such that if I try to use x I get some sort of error > e.g. > > x.do_something() > > #Error: x is definitely not an object anymore > Hi George. Consider what it means for the object to be deleted. When one calls the table.delete_this() method what happens? Is a member variable within the Table object set to None? What members does the table object have? -- Alexander 7D9C597B ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Deleting an object
George Nyoro wrote: class Table: def delete_this(self): #code to delete this object or assign it null or None pass def do_something(self): pass x=Table() x.delete_this() #at this point, I want such that if I try to use x I get some sort of error e.g. x.do_something() #Error: x is definitely not an object anymore Instead of "x.delete_this()", why not just say "del x"? Why try to fight Python, instead of using the tools Python already gives you? Objects cannot delete themselves, because they cannot know all the places they are referenced. If you absolutely have to have something like x.delete_this, then try this: class Table: def __init__(self): self.alive = True def delete_this(self): self.alive = False def do_something(self): if self.alive: print("Doing something.") else: raise TableError("object has been killed") class TableError(RuntimeError): pass -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Deleting an object
George Nyoro wrote: >Last time I tried to post a question regarding this, I was asked to > clarify. Okay so here it is. There is a class called Table and objects are > just tables, you know, matrices, holding different types of data. Thing > is, I want to provide a method where one can delete the object and then if > the user tries using a variable to access a certain method or attributes, > he gets an error. Let me give an example; > > class Table: > def delete_this(self): > #code to delete this object or assign it null or None > pass > > def do_something(self): > pass > x=Table() > x.delete_this() > > #at this point, I want such that if I try to use x I get some sort of > #error > e.g. > > x.do_something() > > #Error: x is definitely not an object anymore > > > All clear? >>> class Parrot: ... def hello(self): ... print("Hello") ... def delete_this(self): ... self.__class__ = DeadParrot ... >>> class DeadParrot: ... def __getattr__(self, name): ... raise Exception("This parrot is no more") ... >>> p = Parrot() >>> p.hello() Hello >>> p.delete_this() >>> p.hello() Traceback (most recent call last): File "", line 1, in File "", line 3, in __getattr__ Exception: This parrot is no more But I don't think it's a good idea... ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Deleting an object
On 29/01/12 15:14, George Nyoro wrote: data. Thing is, I want to provide a method where one can delete the object and then if the user tries using a variable to access a certain method or attributes, he gets an error. Let me give an example; I assume you know about the built in del() function that deletes objects? It works on any kind of object. If you need it to do sometjing fancy(like releasing resources say) you can define your own __del__() method that gets called by Python when the object is deleted - but you rarely need to do that in Python. class Table: def delete_this(self): def do_something(self): x=Table() x.delete_this() #at this point, I want such that if I try to use x I get some sort of error e.g. x = Table() del(x) now referencing x or any attribute or method will give a name error. Here is an example using an int, but any kind of object works: >>> x = 42 >>> x 42 >>> del(x) >>> x Traceback (most recent call last): File "", line 1, in NameError: name 'x' is not defined >>> If thats not what you want you need to come vback and explain what is different about your scenario. -- Alan G 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
Re: [Tutor] Socket Programming
On 1/27/2012 10:13 PM, Steven D'Aprano wrote: Navneet wrote: One more thing I want to add here is, I am trying to create the GUI based chat server.(Attached the programs.) Please do not send large chunks of code like this, unless asked. Instead, you should try to produce a minimal example that demonstrates the problem. It should be: * short (avoid code which has nothing to do with the problem) * self-contained (other people must be able to run it) * correct (it must actually fail in the way you say it fails) See here for more: http://sscce.org/ In cutting your code down to a minimal example, 9 times out of 10 you will solve your problem yourself, and learn something in the process. bash-3.1$ python Client1.py Enter the server address:...9009 Traceback (most recent call last): File "Client1.py", line 53, in c = ClientChat(serverport) File "Client1.py", line 24, in __init__ gui.callGui() File "a:\FedEx\Exp\ClientGui.py", line 37, in callGui sendbutton =Button(f2, width = 5, height = 2, text = "Send", command = C.ClientChat.senddata()) TypeError: unbound method senddata() must be called with ClientChat instance as first argument (got nothing instead) This one is easy. You need to initialize a ClientChat instance first. This may be as simple as: command = C.ClientChat().senddata although I'm not sure if ClientChat requires any arguments. Note that you call the ClientChat class, to create an instance, but you DON'T call the senddata method, since you want to pass the method itself as a callback function. The button will call it for you, when needed. Thanks for the clarification and telling me about SSCCE :) But just a simple thing,,, Can I call a method of another module while creating a GUI. For example C = Tk() .(Some more lines) self.sendbutton =Button(self.f2, width = 5, height = 2, text = "Send", command = .) self.sendbutton.pack(side = LEFT, padx = 10, pady = 10) .(Some more lines) C.mainloop() Because I am getting stuck in a loop. The client is keep on connecting to server without creating a GUI. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Why do you have to close files?
All the replies were very helpful! Thank you very much for helping me out! ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] loop until a keypress
I want to run code until a "enter" is pressed. Well, it shouldn't wait for the user to enter "enter" This is my code: import msvcrtchr = 0while chr != 'q': print "my code", if msvcrt.kbhit(): chr = msvcrt.getch() This isn't working the way I wanted. When ever I press enter, the loop is starting in a new line and continuing. I even added "break" statement in "if" block but it isn't workingCan you tell me how to do that? I am on windows. So, as msvcrt is for windows, I wonder if there is any module that works for both, ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Help Glade Tutorial.
Hi Guys, I am searching for a Glade tutorial, on how to create simple projects Glade with python 1) design a simple interface in glade 2) use the glade interface to write some really simple application with python. I search in goggled i didn't get good tutorials, guide me guys How to start with Glade. -Ganesh Did I learn something today? If not, I wasted it. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help Glade Tutorial.
Which ones did you look at, and why did you not like them? Keep in mind that Glade is an interface builder, and hasn't got anything much to do with the target language, other than requiring there be a libglade library to read the XML files. I actually got started with some articles in Linux Journal, which don't appear high on the google search unless you include those terms. Search for "glade tutorial" or "glade linux journal". Leave Python or pyGTK out of your search for now. You might need a little help with using the XML files glade produces, but that's covered in the pyGTK documentation. It's also in the Linux Journal articles. You can google "pygtk glade" if you need more. Cheers On Monday 30 January 2012, Ganesh Kumar wrote: > Hi Guys, > > I am searching for a Glade tutorial, on how to create simple projects Glade > with python > > 1) design a simple interface in glade > 2) use the glade interface to write some really simple application with > python. > > I search in goggled i didn't get good tutorials, guide me guys How to start > with Glade. > > -Ganesh > > Did I learn something today? If not, I wasted it. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor