Yet another template engine : HYPY

HyPy : means HYperText in PYthon It's yet another template engine, under GPL2 license The main feature is that it let you code yours templates like you code your python. (the indentation defines the structure of the html). So, it's ...

Posted On: Saturday 10th of November 2012 02:19:49 AM Total Views:  498
View Complete with Replies

Related Messages:

How to assign a function to another function   (356 Views)
Hi all what i'm trying to do is this: >>>def foo (): .... return None .... >>>def bar (): .... print "called bar" .... >>>def assigner (): .... foo = bar .... >>>assigner() >>>foo() called bar >>> This piece of code is not working and even trying with >>>def assigner (a, b): .... a = b .... >>>assigner(foo, bar) >>>foo() isn't working. How can I achieve my goal
Re: How to assign a function to another function   (172 Views)
On 9/17/07, Stefano Esposito wrote: > Hi all > > what i'm trying to do is this: > > >>>def foo (): > ... return None > ... > >>>def bar (): > ... print "called bar" > ... > >>>def assigner (): > ... foo = bar > ... You need to tell "assigner()" that foo doesn't belong to the local (function) namespace, but rather comes from the global namespace: In [1]: def foo(): ...: return None ...: In [2]: def bar(): ...: print "called bar" ...: ...: In [3]: def assigner(): ...: global foo ...: foo = bar ...: ...: In [4]: assigner() In [5]: foo() called bar Kurt
Impersonate another user temporarily (Unix and Windows)   (224 Views)
. I'm writing a modification for a FTP server library I'm maintaining. Depending on the system I'd want to temporarily impersonate the logged user to perform actions on filesystem. Something like: try: change_user('user', 'password') os.rmdir('dir') except: print "some error" finally: change_user('old_user', 'password') On Unix I took at look at os.seteuid() and os.setegid() functions and I noticed they could be useful for my purpose. On Windows I have no idea about how could I emulate a similar behaviour. Could someone please point me in the right direction
Re: Yet another comparison of Python Web Frameworks   (164 Views)
Massimo Di Pierro wrote: > happy to hear that. > you may want take a loot at > It is mostly python stuff and will post the code soon. Ah, memories I'm not working on QCD anymore, but I did write a bunch of code a while back to script Mayavi (the old one, not the new Mayavi2) to auto-generate webpages slicing through topological charge configurations, looking for instanton molecules. Your images are a bit small for me to tell what toolkit you're using (Mayavi is VTK based), but if you want, I'd be happy to send you that old code. It probably won't do anything you don't already have, but it was handy. It would slice in any direction (typically t) and generate one PNG per value, with the remaining 3 variables displayed, and isosurfaces computed at 1/4 and 3/4s of the total distribution of values, to conveniently see the instanton/anti-instanton pairs. By spitting out one webpage per field configuration, I could let it run overnight and then the next day quickly have an overview of all the configurations I had (or show them to my advisor). The code was written to read the MILC v5 binary lattice formats, which is what I was using. Just drop me a line if you happen to want any of that code. Cheers, f
Lookup values from one table to another based on a value   (154 Views) a crit : (snip) > > If I flipped the Table being looked up not to repeat, would that make > things easier to look up a value in Don't repeat informations.
Re: Noob: What is a slot? Me trying to understand another's code   (256 Views)
En Tue, 04 Sep 2007 15:03:16 -0300, Carnell, James E escribi: > MY QUESTION: > What is a slot In class Object below the __init__ has a slot. Note: > The slot makes use of a data object called 'percept' that is used in the > TableDrivenAgent(Agent) at the bottom of this post. I am guessing this > is a type of Finite State Machine (I haven't bought the book yet so I am > guessing). The authors appear to be using the term in a very general sense - meaning "something that has to be filled in". That is, you (the programmer) is supposed to "fill" the slot with meaningful code or data. > [...] You subclass Object to get the objects you want. Each object can > have a .__name__ slot (used for output only). > [...] An Agent is a subclass of Object with one required slot, > .program, which should hold a function that takes one argument, the > percept, and returns an action. Note that 'program' is a slot, not a > method. Here they're trying to bind a simple function (not a method) to a name. I don't see the point in forcing things that way, maybe the authors have good reasons. But I'd use a staticmethod instead, perhaps. Note: The C Python source code does use "slots", fields in a structure holding function pointers. For example, filling the nb_add slot in a type object, one can evaluate a+b for instances of that type. -- Gabriel Genellina
How to get inputs for a python program that run from another python program   (213 Views)
I would like to know how to pass keyboard input for a python script which is ran by another script. for eg: import os if __name__=='__main__': print "I will call this other program called" os.system("python") print "" import os if __name__=='__main__': print "press ENTER to display" #code wer if the user hits enter print "hello" #else the user hits any other keyboard button: sys.exit() now wen i run,i want the some function or utility in that can pass the keyboard i/p to .
How best to pass arbitrary parameters from one function to another   (220 Views)
Hi Pythonistas, I'm looking for the best way to pass an arbitrary number and type of variables created by one function to another. They can't be global because they may have different values each time they are used in the second function. So far I'm trying to do something like this: def process_args([list, of, command-line, arguments] ): do stuff return {dictionary : of, local : variables } def main_function( **kwargs ): do stuff return result kw1 = process_args( [some, list] ) kw2 = process_args( [a, different, list] ) for i in main_function( **kw1 ): kw2[ var1 ] = i kw2[ var2 ] = len( i ) for j in main_function(**kw2): print j This only seems to work if I specify a default value for every possible parameter of main_function and also for any others which may be passed to it, which is a bit tedious because there are very many of them but only a few are used in any given execution of the program. Is there a better way to do it Or have I simply made an error
Re: testing if another instance of a script is already running   (209 Views)
Strato wrote: > Hi folks, > > I want to write some kind of test to check at startup if another > instance of my script is already running. > > I don't want to handle writing of a PID file because it is too > Unix/Linux specific way to do this, and I need to keep the code to be > cross-platform. > > I think the better way to achieve this is to use some process control, > but I'm a neebie and I don't see how to do this in a safe and clean way. There's nothing built in to Python to do this, so you'll probably have to roll your own cross-platformness. Of course, there's nothing to stop you from writing pid files under Windows even if it's not the usual way. Or you could just put some conditional code, and use the kernel mutex under Windows, which is the generally recommended technique. Have a look at this thread, for example (among several others): TJG
Tiny yet useful utility   (116 Views)
Process Manager for Windows (http:// It has always been a pain to use applications like Office/Outlook/Matlab/Delphi/Mozilla...Image editing s/w editing s/w They take huge memory... they eat up half of your CPU ....and when you wanna close them, then also they take huge time ..... to get rid off all these... Arif has developed this small utility.... so now ... you can just right click on any application in taskbar and say "Kill"... Also if you wanna increase/decrease the priority of any application, then all you have to do is just one click on the application in the taskbar and say increase/decrease priority... He hopes public will like it and encourage him to add more features... You may check out the list of upcoming features click here Click here to download 300+ people are using Process Manager. If you like Process Manager leave a comment on Process Manger's blog
Re: How best to pass arbitrary parameters from one function to another   (208 Views)
On Tue Sep 30 11:32:41 CEST 2008, Steven D'Aprano >On Tue, 30 Sep 2008 08:58:15 +0000, John O'Hagan wrote: > >> Hi Pythonistas, >> >> I'm looking for the best way to pass an arbitrary number and type of >> variables created by one function to another. They can't be global >> because they may have different values each time they are used in the >> second function. >> >> So far I'm trying to do something like this: >> >> >> def process_args([list, of, command-line, arguments] ): > > >If you are trying to process commandline args, I suggest you don't re- >invent the wheel. Have a look at the two standard modules, optparse and >getopt. Of the two, getopt is probably simpler to get started with, but >optparse is more powerful. >
Calling "def" functions from another file.   (164 Views)
frankrentef a crit : > Newbie here.... > > I'm writing a Python program that has "def" functionality functions > growing in > leaps and bounds. I'm a newbie to Python so be detailed. Is there a > way to create a py file with all the "def's" listed and just call them > from the "program" py file yes. Put all your functions in a .py file, and import that file from the main 'program' file. > How would I do this this is in the FineManual(tm), here: I strongly suggest you read this first, experiment a bit, then come back here if you have any trouble or question. > Say my "def" py > file was named Bad name. 'def' is a reserved word, so you can't name a module (a .py file) that way.
how to give focus to another application   (149 Views)
I would like to know if 1)there is a Python way to tell under which terminal process a Python command-line application is running 2)there is a Python way to tell the OS to give focus to another window. Solutions for Windows, Linux and OS X are welcome, even if OS-specific (of course general solutions are better, but I can kludge & check the platform).
Connecting through another program   (153 Views)
I am attempting to make an addon to a game. The game developers allow what I want to do but in order to comply with the rules I must allow the user to connect with the default client and then I can close it if I don't need it. How would I call the client and take it's connection so I can close it once I am done with it
How python writes text into another windows application   (344 Views)
I am trying to write a simple program that reads data from a source file (Excel sheet, XML file or text file) and then write the data into another application by pasting the data into the applications fields, and jumps from one field to another by writing \t tab. My question is, how do I write the data into another application fields. My target application is the TNT consignment manager. I asked TNT for their API to make my life easier but they refused to release it . I have a software that uses the same way I am looking after to fill in application fields, it is the QuickAddress. Any idea how to achieve that
Re: Yet another comparison of Python Web Frameworks   (152 Views)
> everybody, > > I just joined this mailing list.
Re: calling the function of one class from another class   (171 Views)
Furkan Kuru wrote: > > > On 9/22/07, *Mridula Ramesh* > wrote: > > hi. > > i currently have code structured like this: > > classA(): > def __init__(): > .............. > .............. > > def fnc1(): > .................... > .................... > > > classB(): > def __init__(): > ........................ > ........................ > classA.fnc1() #this is where i get an error > > > TypeError: unbound method fnc1() must be called with classA instance > as first argument (got nothing instead) > > when i do fnc1(classA) i get: > > NameError: global name 'fnc1' is not defined > > am i violating some programming rule by trying to call fnc1 in > classB i am only now learning OO alongside python, so i'm not sure! > also, can someone please tell me where to go for more articles on > the classes and functions and calling them from other places > > thanks a lot! > > mridula. > > -- > > > > > you should create an instance of ClassA: > > a = ClassA() > a.fnc1() > Unfortunately this won't work either, as calling the method on an instance will automatically provide the instance as the first argument to the method call, but the method is defined to take no arguments. > or if you want a static function you should declare the method as static > > classA(): > def __init__(): > .............. > .............. > @staticmethod > def fnc1(): > .................... > .................... Although most often if you want a static function you should just define .... a function! The OP should read through the tutorial, or at least those sections dealing with function and class definitions. It appears (s)he may be trying to write Java in Python. That's never a satisfactory experience. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC/Ltd Skype: holdenweb Sorry, the dog ate my .sigline
adding a static class to another class   (157 Views)
HI, I m trying to start an api in a similar way to the djangic way of Class.objects.all(). Ie objects is a "Manager" class. So: class Foo(object): def __init__(self): self.test = "NEE" class Manager(object): def __init__(self): pass def all(self): return "COCONUTS" Because of how some of the code is set up I cant use I try to use a decorator: def addto(instance): def decorator(f): import new f = new.instancemethod(f, instance, instance.__class__) setattr(instance, "objects", f) return f return decorator class Manager(object): @addto(Foo) def __init__(self): ............. however this only binds the init method to the Foo.objects, so not what I want. If I try using classmethod...then it just says the Foo.objects doesnt exist. Does anyone have any ideas how I can accomplish this using decorators And also preventing more than one Manager instance instantiated at one time. Many
Re: another thread on Python threading   (254 Views)
--- "cgwalters@" wrote: > One random idea is to for Python 3000, make the > equivalent of > __slots__ the default, *but* instead gather > the set of attributes from all member variables set > in __init__. Are you suggesting to do this at startup time or runtime The pitfall here is that to reduce code duplication, you might initialize certain variables in a method called by __init__, because your object might want to return to its initial state. An example might be an object that flipflops between waiting for headers and waiting for payloads. You might have code like this: class MessageReader: def __init__(self, incoming_port): self.incoming_port = incoming_port self.start_waiting_for_headers() def start_waiting_for_headers(self): self.waiting_for_headers = '' self.header = '' self.payload = '' def handle_payload(self): self.do_something_with(self.payload) self.start_waiting_for_headers() # ... ____________________________________________________________________________________ Looking for a deal Find great prices on flights and hotels with Yahoo! FareChase.
access variables from one Python session to another on the samemachine?   (163 Views)
Suppose I have two different command windows going on the same machine, each running their own Python interpreters. Is it possible to access the variables in one of the interpreter- sessions from the other It turns out I have limited control over one of the sessions (i.e. cannot control all the code that is run from there), but complete control over the other. I get the feeling this has been asked before, but I'm not sure how to pose the question in such a way that it would show up on a search. It's confusing.