473,378 Members | 1,370 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

trying to create a dictionary in python, using variables as a value

but I keep getting syntax errors on this one -

adict = {'zid': result[0][0], 'keywords': result{0][1],
'quotations':result[0][2],'citations':result[0]{3]};
zhtml.print_update_form(adict);
result [0][0] = 22L
result [0].[1] = "Agricultural Subsidies, Global Trade', '

result[0][2]] = Lazio, Rick, "Some Trade Barrier1s Won\xe2\x80\x99t
Fall," <i>The New York Times</i>, 8/9/03\\r\\n"

result[0] [3] ='In 2002, the 30 industrial nations of the Organization
for Economic Cooperation and Development spent $311 billion on domestic
agricultural subsidies, which is more than the combined gross domestic
products of all the countries of sub-Saharan Africa. The World Bank
calculated that the European Union\xe2\x80\x99s annual subsidy to dairy
farmers comes out to $913 per cow; this dwarfs sub-Saharan
Africa\xe2\x80\x99s per capita gross domestic product of
$490.\xe2\x80\x9d\\r\\n \\r\\n \\r\\n

result = ((22L, '((22L, 'Agricultural Subsidies, Global Trade', 'Lazio,
Rick, "Some Trade Barrier1s Won\xe2\x80\x99t Fall," <i>The New York
Times</i>, 8/9/03\\r\\n \\r\\n \\r\\n ',
'\xe2\x80\x9cIn 2002, the 30 industrial nations of the Organization for
Economic Cooperation and Development spent $311 billion on domestic
agricultural subsidies, which is more than the combined gross domestic
products of all the countries of sub-Saharan Africa. The World Bank
calculated that the European Union\xe2\x80\x99s annual subsidy to dairy
farmers comes out to $913 per cow; this dwarfs sub-Saharan
Africa\xe2\x80\x99s per capita gross domestic product of
$490.\xe2\x80\x9d\\r\\n \\r\\n \\r\\n '),)n ',
'\xe2\x80\x9cIn 2002, the 30 industrial nations of the Organization for
Economic Cooperation and Development spent $311 billion on domestic
agricultural subsidies, which is more than the combined gross domestic
products of all the countries of sub-Saharan Africa. The World Bank
calculated that the European Union\xe2\x80\x99s annual subsidy to dairy
farmers comes out to $913 per cow; this dwarfs sub-Saharan
Africa\xe2\x80\x99s per capita gross domestic product of
$490.\xe2\x80\x9d\\r\\n \\r\\n \\r\\n '),)
thanks again for your wonderful assistance.

bests,

-rsr-

Nov 20 '06 #1
6 1217

"ronrsr" <ro****@gmail.comwrote in message
news:11*********************@k70g2000cwa.googlegro ups.com...
but I keep getting syntax errors on this one -

adict = {'zid': result[0][0], 'keywords': result{0][1],
The interpreter puts a ^ under the char where it sees a problem.
Cut and paste above into IDLE shell and it will highlight the problem.
Or just read carefully again ;-)
Terry Jan Reedy

Nov 20 '06 #2
ronrsr wrote:
but I keep getting syntax errors on this one -
On this one what? It would help very much if you showed the one
statement that is getting the syntax error.
>
adict = {'zid': result[0][0], 'keywords': result{0][1],
'quotations':result[0][2],'citations':result[0]{3]};
zhtml.print_update_form(adict);
If you were to set out your code neatly, the *two* syntax errors would
be somewhat more
obvious on inspection, and would enable easy detection when you tried
to load the file.

# The following is meant to have the "result"s aligned vertically ...
adict = {
'zid': result[0][0],
'keywords': result{0][1],
'quotations': result[0][2],
'citations': result[0]{3],
}
zhtml.print_update_form(adict)

===
C:\junk>ronsr2.py
File "C:\junk\ronsr2.py", line 3
'keywords': result{0][1],
^
SyntaxError: invalid syntax
>
result [0][0] = 22L
result [0].[1] = "Agricultural Subsidies, Global Trade', '
The above looks very much like a syntax error to me (dot between [0]
and [1])
>
result[0][2]] = Lazio, Rick, "Some Trade Barrier1s Won\xe2\x80\x99t
Fall," <i>The New York Times</i>, 8/9/03\\r\\n"
While not strictly syntax errors, I doubt very much whether Lazio and
Rick are intentional variable names! And they're not (looking at
"result" below)!! Why are you retyping all of this stuff? If you think
it's a help with discovering why there's a syntax error in the first
line, it's not a help, it's quite irrelevant. A syntax error means that
the statement is not a valid Python statement -- nothing to do with the
contents of any variables mentioned in the statement.
>
result[0] [3] ='In 2002, the 30 industrial nations of the Organization
for Economic Cooperation and Development spent $311 billion on domestic
agricultural subsidies, which is more than the combined gross domestic
products of all the countries of sub-Saharan Africa. The World Bank
calculated that the European Union\xe2\x80\x99s annual subsidy to dairy
farmers comes out to $913 per cow; this dwarfs sub-Saharan
Africa\xe2\x80\x99s per capita gross domestic product of
$490.\xe2\x80\x9d\\r\\n \\r\\n \\r\\n

result = ((22L, '((22L, 'Agricultural Subsidies, Global Trade', 'Lazio,
Rick, "Some Trade Barrier1s Won\xe2\x80\x99t Fall," <i>The New York
Times</i>, 8/9/03\\r\\n \\r\\n \\r\\n ',
'\xe2\x80\x9cIn 2002, the 30 industrial nations of the Organization for
Economic Cooperation and Development spent $311 billion on domestic
agricultural subsidies, which is more than the combined gross domestic
products of all the countries of sub-Saharan Africa. The World Bank
calculated that the European Union\xe2\x80\x99s annual subsidy to dairy
farmers comes out to $913 per cow; this dwarfs sub-Saharan
Africa\xe2\x80\x99s per capita gross domestic product of
$490.\xe2\x80\x9d\\r\\n \\r\\n \\r\\n '),)n ',
'\xe2\x80\x9cIn 2002, the 30 industrial nations of the Organization for
Economic Cooperation and Development spent $311 billion on domestic
agricultural subsidies, which is more than the combined gross domestic
products of all the countries of sub-Saharan Africa. The World Bank
calculated that the European Union\xe2\x80\x99s annual subsidy to dairy
farmers comes out to $913 per cow; this dwarfs sub-Saharan
Africa\xe2\x80\x99s per capita gross domestic product of
$490.\xe2\x80\x9d\\r\\n \\r\\n \\r\\n '),)
Nov 20 '06 #3
John Machin wrote:
On this one what? It would help very much if you showed the one
statement that is getting the syntax error.
on which statement does he *not* get a syntax error?

</F>

Nov 20 '06 #4

"ronrsr" <ro****@gmail.comwrote in message
news:11*********************@k70g2000cwa.googlegro ups.com...
but I keep getting syntax errors on this one -

adict = {'zid': result[0][0], 'keywords': result{0][1],
'quotations':result[0][2],'citations':result[0]{3]};
Probably because it has some syntax errors in it. Look carefully at your
"[" characters, you have typed some of them as "{".

-- Paul
Nov 20 '06 #5
At Monday 20/11/2006 04:40, ronrsr wrote:
>but I keep getting syntax errors on this one -

adict = {'zid': result[0][0], 'keywords': result{0][1],
'quotations':result[0][2],'citations':result[0]{3]};
zhtml.print_update_form(adict);
There *are* syntax errors, result{0] should be result[0], and
result[0]{3] should be result[0][3]
--
Gabriel Genellina
Softlab SRL

__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ˇgratis!
ˇAbrí tu cuenta ya! - http://correo.yahoo.com.ar
Nov 20 '06 #6
Fredrik Lundh wrote:
John Machin wrote:
On this one what? It would help very much if you showed the one
statement that is getting the syntax error.

on which statement does he *not* get a syntax error?
A clarification:

The first statement *contains* two syntax errors. There are various
others sprinkled throughout what he has seemingly typed in with
presumably explanatory intent.

Even if that were in fact his source file, he would only *get* one
Syntax Error *message*. Python evidently has inherited its error
handling from Dijkstra's first Algol 60 compiler, which according to
legend, had a similar modus operandi.

HTH,
John

Nov 20 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Don Bruder | last post by:
A week or two ago, I asked here about porting Python to C. Got some good answers (Note 1) but now I've got another question. Actually, more a request for clarification of a topic that both the...
2
by: John Mudd | last post by:
I must be missing something here. It's clearly faster to lookup an item directly in a dictionary than to scan through a list. So when I have a large lookup table I always load it in the form of a...
7
by: Thomas Philips | last post by:
I want to print "1 spam 4 you" using a formatted string that gets its inputs from the dictionary d={'n1':1, 's1':'spam', 'n2':4}. To do so, I write >>> x="%('n1')d %('s1')s %('n2')d you" >>> x...
8
by: Jack Carter | last post by:
I have been delegated to produce a tool that has python embedded in it. The desire is to have a command line interface that inherits all the python scripting functionality so people can use the...
57
by: Egor Bolonev | last post by:
why functions created with lambda forms cannot contain statements? how to get unnamed function with statements?
8
by: Rodd Snook | last post by:
I have an application which makes extensive use of the Scripting.Dictionary object. I'm not doing anything silly like putting them outside the page scope -- just creating quite a few of them and...
1
by: Crutcher | last post by:
I've been playing with dictionary subtypes for custom environments, and I encountered a strange interaction between exec, dictionary subtypes, and global variables. I've attached a test program,...
3
by: galadhad | last post by:
Okay, here goes. I'm new to Python (and relatively new to programming/scripting in general - I understand basics, but complex concepts are still beyond my limited knowledge). I am working on a...
4
by: icarus | last post by:
global_vars.py has the global variables set_var.py changes one of the values on the global variables (don't close it or terminate) get_var.py retrieves the recently value changed (triggered right...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.