So I'm working on a script that will automatically download certain files from IRC XDCC bots when run. These requests are asynchronous and there can be a varying number, depending on a config file so I wanted to keep the file handles in a hash table or library so they could easily be referenced based on who the 开发者_高级运维file sender was and the file they are sending (read during a triggered event). Python is complaining saying SyntaxError: can't assign to function call
so I'm guessing it won't work quite how I want.
Any easier way to do this? Am I barking up the wrong tree here?
Thanks! -Russell
The problem is that the left side of an assignment statement must be an lvalue, that is something that the compiler knows has a memory address, like a variable. It is the same in other programming languages. The return value of a function is an rvalue, or a pure value.
These are other illegal assignments:
f() = 1
2 = 1
None = 0
[1,2] = []
Note that the follwing are syntactically correct because the compiler knows how to compute an address for the memory location to be assigned:
f().a = None
[1,2][0] = 0
Create an empty hash:
files = {}
Add items to the hash:
files["gin"] = open('ginpachi.txt','w')
files["ahq"] = open('ahq[DaBomb].txt','w')
Reference them like you would a normal file handler
files["gin"].close()
...
Unfortunately, there wasn't any information on this on the web (specifically with hashes and file handles). Case closed
精彩评论