| |
| |
| |
|
Page: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
Comments:
<0> arie_: what exactly do you mean? <1> i know i can import it <0> arie_: what kind of files? textfiles? <1> Noet, py files <0> ah <0> and you want some kind of inter-process-communication? <1> i can't import both files <1> i mean: file1: import file2 file2: import file1 <1> that isn't possible, is it? <1> how can i make this possible <0> arie_: what exactly do you want to do? <1> i can't really explain <1> i shall try it myself again <0> arie_: hmm ok <2> arie: move code that needs to be shared between file1 and file2 to a new module, import that in both modules <3> arie_: it's possible in some circumstances
<4> arie_: why not have file3: import file1,file2 <0> VladDrac: ah that's what he meant ;) <3> arie_: http://www.python.org/doc/faq/programming.html#how-can-i-have-modules-that-mutually-import-each-other <0> VladDrac: i thought he had a runtime-problem <5> ok... im getting the hang of python great.. and its by far the nicest langauge ive used in a while... but im stuck with something <5> im trying to parse a file, break down the file and use it to build a set of string variables to execute as functions <1> tnx for help <6> how can i append to a dict? <5> everythign but the last bit is easy :) <1> i didn't suspect you would understand my confusing story but you did!!! <7> Lucractius_Azorz: You can use eval (for expressions) or exec (for statements) to evaluate code <5> i want cmdlist[1] to become foo() <5> so eval cmdlist[#] <5> ? <4> Lucractius_Azorz: see also http://www.python.org/doc/faq/programming.html#how-do-i-use-strings-to-call-functions-methods <7> Lucractius_Azorz: Maybe. Hard to say with so little info. If all you have is a string with a function name, you can look it up in some dictionary, like using getattr to find it as a method in an object (including modules), or globals() to search in global variables. <5> pythonologist, i knew it would be somewhere ... i have this problem in almost all languages i use lol... someones usualy got a way to do it, but it looks like python beats java hands down for simplicity... reverse indexed lookup tables... what a pain <8> how do i flush the sending buffer, so i can be sure that what's being sent is sent out "alone"? <5> Erwin, its a data proccessing util, so its basicly using a text config file to pick out specific variables from a pool of data at hand and then print them out :) <9> hi all, i have this: ('SIAD_CLI', {'CLI_DES': 'NOME'}) <9> ('SIAD_CLI', {'CLI_COD': 'CODIGO'}) how can i make it into this: ('SIAD_CLI', {'CLI_DES': 'NOME'},{'CLI_COD': 'CODIGO'}), being more specific i want to join the lists that have the same first key, is there any simple way? <8> basically so i can do: if data == "SOMETHING": at the receiving end <8> without having to think about data received before that <8> (i want to mark the end of a large data sending) <7> zamba: Impossible in TCP. TCP is a stream, there are no packets. Data will arrive in order, but you can't control what chunks it willl arrive in. <0> sapo: without having tried it - what happens if you use foo[SIAD_CLI].update(bar[SIAD_CLI])? <7> zamba: If you need to send a bunch of data you could e.g. send the length first, or use some special char that won't occur in the message. <9> hds, i got this: TypeError: list indices must be integers <8> Erwin: i don't know the length beforehand <5> pythonologist, Erwin, thanks both of you :) eval solved the issue in no time :) <7> zamba: Well, find some message terminator that you can guarantee will not occur in the normal data, and split up messages based on that <7> zamba: For many protocols, that is simply a newline. <10> you could also copy http's chunked encoding <11> is there a locale-aware way to do "somestring".lower()? <7> Convert to unicode <11> seems to work, thanks <12> How can I print a float with 2 numbers after the .dot.. like 2.34 instead of 2.434323 .. I C++ I can use print ("%f.2") <12> eh printf in C++ of course :) <7> print "%.2f" % somefloat -- just like in C <8> Erwin: i tried the following: data = self.socket.recv(1024) <8> and then if "END\r\n" in data: to break it <7> zamba: You can't do that. <8> Erwin: cool, why not? <7> zamba: You must buffer all data you've received and not processed and search in that. <8> Erwin: example? <7> zamba: There is absolute no guarantee that one send will translate into one recv. TCP is a stream. <8> Erwin: oh, no.. this is in a while loop <8> Erwin: while 1: around it <11> packet boundaries is the **** <7> zamba: And? <8> then i break inside the if-test <8> while 1: <7> zamba: One receive might get 'EN' and the other 'D\r\n' <12> oh yes stupid me.. <8> Erwin: well, i'm sending chunks of data in 1024 bytes <13> zamba: the chunks you send and the chunks you recv don't have anything eo do with each other <8> hm, ok.. how do i make this work, then? <7> I just told you. <8> the problem has been that it breaks too often, the opposite is not the problem <8> not breaking, i mean <13> zamba: you receive data into the end of some buffer, and process the beginning of that buffer
<8> hm.. i think i understand the theory, but not the implementation of it :) <7> buffer = buffer + dataReceived <7> Here's your implementation. <7> and then you can say: if terminator in buffer: message, buffer = buffer.split(terminator, 1) <8> ah, i think i understand <8> thanks <14> hi ppl. Can anyone tell me how I can enumerate a gconf key? <14> i'm trying to write a simple compiz control panel.. but would rather create the UI based on the gconf keys rather than hardcode paths <9> anyone could help me solving this? i have this list: [('SIAD_CLI', {'CLI_DES': 'NOME'}), ('SIAD_CLI', {'CLI_COD': 'CODIGO'}), ('SIAD_PRO', {'PRO_DES': 'DESPRO'}), ('SIAD_PRO', {'PRO_COD': 'CODIGO'})] <9> how can i join the turples with same name.. so it would be like this: [('SIAD_CLI',{'CLI_DES':'NOME'},{'CLI_COD':'CODIGO'}) <9> its like joining what is repeating <15> hi again ;D <15> missed ya, lol <16> sapo it might be even easier to put each group in one dictionary, so it winds up being: [('SIAD_CLI',{'CLI_DES':'NOME'},{'CLI_COD':'CODIGO'}) <16> ugh <16> sapo it might be even easier to put each group in one dictionary, so it winds up being: [('SIAD_CLI',{'CLI_DES':'NOME', 'CLI_COD':'CODIGO'}) ... <9> Zalamander, the problem is that i m loading a config file.. and i m looping.. so it repeats =/ <16> either way, it's just a matter of juggling items <9> Zalamander, here is my code: for campo in cfg.items(item[1]): <9> estrutura.append((item[1],{campo[0].upper():campo[1].upper()})) <9> it prints out: [('SIAD_CLI', {'CLI_DES': 'NOME'}), ('SIAD_CLI', {'CLI_COD': 'CODIGO'}), ('SIAD_PRO', {'PRO_DES': 'DESPRO'}), ('SIAD_PRO', {'PRO_COD': 'CODIGO'})] <16> sapo instead of "estrutura.append..." you could use a dictionary: estrutura.setdefault(item[1], {}).update({campo[0].upper():campo[1].upper()}) <17> maybe you should make a dictionary of dictionaries <17> then when you add a dictionary itll automatically join what's repeating <17> and then convert it back to a list <16> sapo that will naturally group everything <16> to get back to the list then, just do "estrutura.items()" <9> Zalamander, thanx man.. this worked like a charm: estrutura.setdefault(item[1], {}).update({campo[0].upper():campo[1].upper()}) <9> now it outputs: 'SIAD_CLI': {'CLI_DES': 'NOME', 'CLI_COD': 'CODIGO'}, 'SIAD_PRO': {'PRO_DES': 'DESPRO', 'PRO_COD': 'CODIGO'}} <9> Zalamander, =* <16> ayep :-) <18> how can i make a post request to a webserver with python <7> ludde: using urllib.urlopen. see the docs. <18> it doesn't seem to support post? <18> hm <7> What? <18> or, data is post <7> If the url uses the http: scheme identifier, the optional data argument may be given to specify a POST request (normally the request type is GET). <7> ^^^ Straight from the docs <18> yeah.. hm <18> does python have any facility for application/x-multipart-form encode the contents or whatever the encoding is called <18> s/for/to/ <18> it seems like it supports only application/x-www-form-urlencoded <18> but i need to post a file to a php script. <19> ludde: I typed "python POST multipart" into google and a number of useful-seeming items show up <10> also, creating something yourself is not that hard ;) <18> ok lemme try that <20> Hello, I'm basically trying to create the functionality of a function pointer in a Python cl***... Can I simply do instance.function = myfunction ? <20> And then call the function by means of instance.function(args) ? <17> i dont know what youre trying to do but that looks like it would work <20> The cl*** is a simple A*-agent, it needs two functions to calculate it's path. I want to be able to change the functions it uses easily. <17> oh, i see <17> that should work, yeah. <20> inhahe: Ah, okay, thanks. My Python reference weren't very clear on that particular issue. <21> xarragon, you can't, because methods and functions are not entirely the same. <21> And generally speaking, functions, cl***es, whatever, are first-cl*** objects. They are just regular values. <20> I could put the functions in the agent cl***, thereby turning them into methods? <21> I think that what you want to do is to p*** the functions as arguments to a method, although I could be wrong. <22> TFK, can't you use setattr instead of a.meth = newmeth ? <20> Or how should this be done then? <21> Yango, it's exactly the same thing, and suffers from the same problem (*if* newmeth is a regular function) <21> xarragon, what exactly are you trying to do? <16> a function can be externally ***igned to a method name of an instance object, can it not? <16> so long as it allows that the first input will be "self" <21> That won't work as expected. <20> The agent has a method, "think()", which will run the two funktions on a set of nodes, getting a value for each node as a result. I COULD just hard-code the name of the functions, but I'd like to switch functions easily. <23> Cl***.do_something <- function, c = Cl***(); c.do_something <- method <21> http://rafb.net/paste/results/KSfpPv16.html <20> All I need is the equivialent of a function pointer from C, operating on a homogenous set of functions... <16> xarragon you can use getattr() to retrieve a function by name dynamically <20> "homogenous" meaning that they all have the same return value and arguments. <21> He doesn't need any of that. <22> xarragon, it works if you replace it for a method (not even in the same cl***) <21> Where are you getting the two functions from?
Return to
#python or Go to some related
logs:
qmail-tcpok: not found source list apt phpnuke downloader 4x suse californian accents html2tex Linux #gentoo iptables: Unknown error 4294967295 starting erealz cocoasql tutorial #perl
|
|