Take the 2-minute tour ×

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

share|improve this question
Could you show the code that produces the error? There is information about the error message at velocityreviews.com/forums/… –  Apalala Mar 15 '11 at 19:10
Please post a snippet of code to show us what the error is. That SyntaxError can easily be reproduced by (lambda: 1)() += 1 but I'm guessing that's not your problem :) sscce.org –  Mahmoud Abdelkader Mar 15 '11 at 19:12
@Mahmoud That is the problem. See the web page I referenced. It is the same in C and any other language. The target of an assignment must be an lvalue. Note that (lambda: 1)()[0] += 1 doesn't generate a syntax but a runtime error. –  Apalala Mar 15 '11 at 19:18
SyntaxError simply means that what you types in is not valid Python. The problem you're trying to solve has nothing to do with it. So, look at the trackeback, find the line and post it if you cant figure it out. –  Jochen Ritzel Mar 15 '11 at 19:23
ah! after some searching I found the answer myself. –  Russell C Mar 15 '11 at 19:28
add comment

2 Answers

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
share|improve this answer
what exactly is an 'lvalue'? –  Russell C Mar 15 '11 at 19:25
A value that can be used on the left side of an assignment. –  Glenn Maynard Mar 15 '11 at 19:32
add comment

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


Unfortunately, there wasn't any information on this on the web (specifically with hashes and file handles). Case closed

share|improve this answer
add comment

Your Answer


