Why force this into one line? Two weeks from now a user will put a space somewhere, or want to use quotes and you have to go unwind the code. Just make a function now which handles the input and be done with it. It also means you can use unit tests to ensure it works and stays working.
Given this input:
foo=bar
#skip me
bar=baz
baz=foo
#skip me too!
The following code will handle it all nicely.
import sys
def parse_line(input):
key, value = input.split('=')
key = key.strip() # handles key = value as well as key=value
value = value.strip()
return key, value
if __name__ == '__main__':
data = {}
with open(sys.argv[1]) as fp:
for line in fp:
line = line.strip()
if not line or line.startswith('#'):
continue
key, value = parse_line(input)
data[key] = value
print data
BTW, I like poke's suggestion of using ConfigParser. But the hack of adding a section may or may not work for everyone.
If you want to move the comment checking into the parse_line() function you could return None, None and check for that before putting the key/value pair into the dictionary.