SyntaxError: Invalid Syntax.
no matter where I place this imported file,the statement after it in the main program gets a syntax error, regardless of the syntax. I think I may have changed something in this file, but I'm stuck. Can anyone help? #!/usr/local/bin/python # Copyright 2004 by Stephen Masterman #Change the db connection details here. import MySQLdb def connect(): return = MySQLdb.connect (host = "db91x..com", user = "", passwd = "x", db = "homebase_zingers" ); -- http://mail.python.org/mailman/listinfo/python-list
Re: SyntaxError: Invalid Syntax.
here's some of the surrounding code from the main program:
querystring = querystring + " ORDER BY keywords ";
#SQL
import zsql
zc = zsql.connect()
print("return from open")
zq = zc.query(querystring).dictresult()
ronrsr wrote:
> no matter where I place this imported file,the statement after it in
> the main program gets a syntax error, regardless of the syntax.
>
> I think I may have changed something in this file, but I'm stuck. Can
> anyone help?
>
> #!/usr/local/bin/python
> # Copyright 2004 by Stephen Masterman
>
> #Change the db connection details here.
>
>
> import MySQLdb
>
>
>
>
> def connect():
>
>
>return = MySQLdb.connect (host = "db91x..com",
>user = "",
> passwd = "x",
> db = "homebase_zingers"
>);
--
http://mail.python.org/mailman/listinfo/python-list
Re: SyntaxError: Invalid Syntax.
thanks for the speedy answer. what i meant was: return MySQLdb.connect (host = "db91b.pair.com", user = "homebase", passwd = "Newspaper2", db = "homebase_zingers" ); but even when I have that, I still get the same error. bests, -rsr- ronrsr wrote: > here's some of t -- http://mail.python.org/mailman/listinfo/python-list
Re: SyntaxError: Invalid Syntax.
the exact code that is triggering the error message is: zc = zsql.connect() exact error message: SyntaxError: Invalid Syntax but any statement that follows the import statement will trigger it. bests, r-sr- Roberto Bonvallet wrote: > ronrsr wrote: > > thanks for the speedy answer. what i meant was: > > > Could you please copy and paste the exact code that is triggering the > error, and the exact error message? > > (BTW, in Python you don't need to end your statements with a semi-colon) > -- > Roberto Bonvallet -- http://mail.python.org/mailman/listinfo/python-list
Re: SyntaxError: Invalid Syntax.
the syntax error comes in the main program, in any line that follows the import statement. ronrsr wrote: > the exact code that is triggering the error message is: > > zc = zsql.connect() > > > exact error message: SyntaxError: Invalid Syntax > > > but any statement that follows the import statement will trigger it. > > bests, > > r-sr- > > > > > Roberto Bonvallet wrote: > > ronrsr wrote: > > > thanks for the speedy answer. what i meant was: > > > > > > Could you please copy and paste the exact code that is triggering the > > error, and the exact error message? > > > > (BTW, in Python you don't need to end your statements with a semi-colon) > > -- > > Roberto Bonvallet -- http://mail.python.org/mailman/listinfo/python-list
format requires a mapping?
what is python trying to tell me here? does it have to do with formatting the string. Keywords and Zinger are fields in my database. print """ Keywords Zinger TypeError: format requires a mapping thanks much in advance, -rsr- -- http://mail.python.org/mailman/listinfo/python-list
how do i map this?
I think I am passing the wrong argument to the Print_row routine:
Traceback (most recent call last):
File "index.py", line 91, in ?
zhtml.print_row(record)
File "/usr/www/users/homebase/realprogress/zingers/zhtml.py", line
154, in pri
nt_row
print """
TypeError: format requires a mapping
[EMAIL PROTECTED]
routine from zhtml.py:
#row is a dictionary with keys: zid, keywords, citation, quotation
def print_row(row):
print """
%(keywords)s
%(quotation)s
%(citation)s
"""
code from index.py:
cursor.execute(querystring);
# get the resultset as a tuple
result = cursor.fetchall()
# iterate through resultset
for record in result:
print record[0] , "-->", record[1]
#zq = zc.query(querystring).dictresult()
#HTML
import zhtml
zhtml.print_start_html()
zhtml.print_header("Frankie's Zingers")
if form.has_key("printview"):
print ("thenxx")
zhtml.printp_start_table()
zhtml.printp_title_row()
for record in result:
zhtml.printp_row(record[row])
else:
# print ("xelsex",record[1]);
zhtml.print_top_controls(k=k,c=c,q=q)
zhtml.print_start_table()
zhtml.print_title_row()
zhtml.print_search_row(k=k,c=c,q=q)
for record in result:
print(record);
zhtml.print_row(record)
zhtml.print_end_table()
zhtml.print_end_html()
how do i go about mapping that, if tha'ts what I need to do.
thanks again for your help.
bests,
-rsr-
--
http://mail.python.org/mailman/listinfo/python-list
Printing database output in tabular form
when I try to print a web table containing output from a database, I am
getting more info than I want- -
I would like this to print w'o the array('c',AND I'd like the
control characters to print as HTML control chars.
array('c', '- "In the boom years of 1990-1997 developing countries paid
more in debt service than they received in new assistance."
\\r\\n\\r\\n- "Africa pays out $13.5 billion in debt service every
year." \\r\\n\\r\\n- "Africa spends four times as much on debt
repayment a')
Thanks very much for your assistance.
bests,
-rsr-
--
http://mail.python.org/mailman/listinfo/python-list
Re: Printing database output in tabular form
On Nov 13, 2:48 pm, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> ronrsr wrote:
> > when I try to print a web table containing output from a database, I am
> > getting more info than I want- -
>
> > I would like this to print w'o the array('c',arrays instead of strings?
> > what database is this, and how is that
> column defined ?
>
>
It is a MySQL database - those columns are defined as BLOBs
bests,
-rsr-
--
http://mail.python.org/mailman/listinfo/python-list
Re: Printing database output in tabular form
I just changed the database to be a TEXT field, and that took care of the array() stuff - Now, I'm trying to convert the formatting codes to html. thanks for your help. bests, r0sr- -- http://mail.python.org/mailman/listinfo/python-list
determining the bounds of a tuple returned from a database
here is my result.
How do I determine the number of tuples in this array, returned from a
mysql database?
How do I determine the number of characters or entry in each tuple?
thanks very much for your assistance,
-rsr-
(('Agricultural subsidies; Foreign aid',), ('Agriculture; Sustainable
Agriculture - Support; Organic Agriculture; Pesticides, US, Childhood
Development, Birth Defects; Toxic Chemicals',), ('Antibiotics,
Animals',), ('Agricultural Subsidies, Global Trade',), ('Agricultural
Subsidies',), ('Biodiversity',), ('Citizen Activism',), ('Community
Gardens',), ('Cooperatives',), ('Dieting',), ('Agriculture, Cotton',),
('Agriculture, Global Trade',), ('Pesticides, Monsanto',),
('Agriculture, Seed',), ('Coffee, Hunger',), ('Pollution, Water,
Feedlots',), ('Food Prices',), ('Agriculture, Workers',), ('Animal
Feed, Corn, Pesticides',), ('Aquaculture',), ('Chemical Warfare',),
('Compost',), ('Debt',), ('Consumerism',), ('Fear',), ('Pesticides, US,
Childhood Development, Birth Defects',), ('Corporate Reform,
Personhood (Dem. Book)',), ('Corporate Reform, Personhood, Farming
(Dem. Book)',), ('Crime Rates, Legislation, Education',), ('Debt,
Credit Cards',), ('Democracy',), ('Population, World',), ('Income',),
('Democracy, Corporate Personhood, Porter Township (Dem. Book)',),
('Disaster Relief',), ('Dwellings, Slums',), ('Economics, Mexico',),
('Economy, Local',), ('Education, Protests',), ('Endangered Habitat,
Rainforest',), ('Endangered Species',), ('Endangered Species,
Extinction',), ('antibiotics, livestock',), ('Pesticides, Water',),
('Environment, Environmentalist',), ('Food, Hunger, Agriculture, Aid,
World, Development',), ('Agriculture, Cotton Trade',), ('Agriculture,
Cotton, Africa',), ('Environment, Energy',), ('Fair Trade (Dem.
Book)',), ('Farmland, Sprawl',), ('Fast Food, Globalization,
Mapping',), ('depression, mental illness, mood disorders',), ('Economic
Democracy, Corporate Personhood',), ('Brazil, citizen activism, hope,
inspiration, labor issues',), ('citizen activism, advice, hope',),
('Pharmaceuticals, Medicine, Drugs',), ('Community Investing',),
('Environment, Consumer Waste Reduction, Consumer Behavior and
Taxes',), ('Hunger, US, Poverty',), ('FERTILITY, Women',),
('Corporatism, Environment',), ('Economic Democracy, Corporate
Farming',), ('Economic Democracy, Inspiration',), ('FEAR
(Fearlessness)',), ('Federal budget, military spending, foreign
cultural exchange programs',), ('Fish Farming',), ('Fish population,
commercial fishing industry',), ('GMO, BT Cotton',), ('Food borne
Illness, Water',), ('Food Charity',), ('Food Charity, Urban Farming',),
('Food Consumption, Luxury',), ('Food Cost, international',), ('Food
Disposal, Waste',), ('Food stamps, eligibility for',), ('Food,
expenditure on',), ('Foreign Aid',), ('Genetics, Food, Agriculture,
International',), ('Global Policy, Bush Administration',), ('Global
Trade, food',), ('Global Trade, free trade, clothing',),
('Globalization',), ('GMO, SACTO Protests',), ('GMO, Wheat, trade',),
('Happiness and income',), ('Health Care - Spending',), ('Hope',),
('Hope, inspirational quote',), ('Human Cloning',), ('Hunger',),
('Hunger, income',), ('IMF, Argentina',), ('IMF, failings',),
('Inequality',), ('INEQUALITY, GLOBALIZATION, POVERTY',), ('Inequality,
Globalization, Latin America',), ('Inspiration',), ('Junk Food',),
('Junk Food, Soft Drinks',), ('Junk Food ,Children, Education,
Media',), ('Junk Food, Education, Children, Nutrition',), ('Junk Food,
Global, Coke',), ('Junk Food, McDonald\x92s',), ('Junk Food,
McDonald\x92s, Global',), ('Junk Food, Soft Drinks, Water',), ('Junk
Food, Education, Nutrition, Childhood Illness',), ('Junk food,
Nutrition, Schools',), ('Labor',), ('Labor Issues, Agriculture,
Sustainable Agriculture Support',), ('Labor Issues, Employee
Ownership',), ('Land Reform, Brazil, Infant mortality',),
('Livestock',), ('Meat',), ('Meat, Brazil, Soybeans, Deforestation',),
('Meat, concentration',), ('Meat, Recalls, Contamination',), ('Meat,
Recalls',), ('Media',), ('Microloans',), ('Military Spending',),
('Nutrition Programs, School Meals, Snapple',), ('Nutrition,
Finland',), ('Obesity',), ('Obesity, Childhood',), ('Obesity,
Africa',), ('Organic Food',), ('Obesity, Global',), ('Obesity, related
illnesses',), ('Obesity, related illnesses, children',), ('Oil',),
('Organic Agriculture',), ('Organic Agriculture, Growth',), ('Organic
Agriculture, Nutrition',), ('Organic Agriculture, Productivity',),
('Organic food prices',), ('Community',), ('Corporate Concentration',),
('Community Gardens, Urban Gardens',), ('Pollution, Air, CO2
emissions',), ('Population, Water',), ('Poverty, Aid',), ('Poverty,
World Bank, Hunger',), ('Organic Produce',), ('Organic Produce,
Farmer\x92s Markets, CSA Community Initiatives (Dem. Book)',),
('Pakistan, Education, Poverty, Terrorism',), ('Pesticides',),
('Pollution, US',), ('Population, Women',), ('Poverty, Labor Issues',),
('t2',), ('Agriculture, Subsidies, Farming, Ranching, Government,
Livestock,
Re: determining the bounds of a tuple returned from a database
it looks like the len() function is the one I want.
for: len(result) - i get 248,
but for len(result[0]) or len(result[1]) i always get 0.
ronrsr wrote:
> here is my result.
> How do I determine the number of tuples in this array, returned from a
> mysql database?
>
> How do I determine the number of characters or entry in each tuple?
>
> thanks very much for your assistance,
>
> -rsr-
>
>
> (('Agricultural subsidies; Foreign aid',), ('Agriculture; Sustainable
> Agriculture - Support; Organic Agriculture; Pesticides, US, Childhood
> Development, Birth Defects; Toxic Chemicals',), ('Antibiotics,
> Animals',), ('Agricultural Subsidies, Global Trade',), ('Agricultural
> Subsidies',), ('Biodiversity',), ('Citizen Activism',), ('Community
> Gardens',), ('Cooperatives',), ('Dieting',), ('Agriculture, Cotton',),
> ('Agriculture, Global Trade',), ('Pesticides, Monsanto',),
> ('Agriculture, Seed',), ('Coffee, Hunger',), ('Pollution, Water,
> Feedlots',), ('Food Prices',), ('Agriculture, Workers',), ('Animal
> Feed, Corn, Pesticides',), ('Aquaculture',), ('Chemical Warfare',),
> ('Compost',), ('Debt',), ('Consumerism',), ('Fear',), ('Pesticides, US,
> Childhood Development, Birth Defects',), ('Corporate Reform,
> Personhood (Dem. Book)',), ('Corporate Reform, Personhood, Farming
> (Dem. Book)',), ('Crime Rates, Legislation, Education',), ('Debt,
> Credit Cards',), ('Democracy',), ('Population, World',), ('Income',),
> ('Democracy, Corporate Personhood, Porter Township (Dem. Book)',),
> ('Disaster Relief',), ('Dwellings, Slums',), ('Economics, Mexico',),
> ('Economy, Local',), ('Education, Protests',), ('Endangered Habitat,
> Rainforest',), ('Endangered Species',), ('Endangered Species,
> Extinction',), ('antibiotics, livestock',), ('Pesticides, Water',),
> ('Environment, Environmentalist',), ('Food, Hunger, Agriculture, Aid,
> World, Development',), ('Agriculture, Cotton Trade',), ('Agriculture,
> Cotton, Africa',), ('Environment, Energy',), ('Fair Trade (Dem.
> Book)',), ('Farmland, Sprawl',), ('Fast Food, Globalization,
> Mapping',), ('depression, mental illness, mood disorders',), ('Economic
> Democracy, Corporate Personhood',), ('Brazil, citizen activism, hope,
> inspiration, labor issues',), ('citizen activism, advice, hope',),
> ('Pharmaceuticals, Medicine, Drugs',), ('Community Investing',),
> ('Environment, Consumer Waste Reduction, Consumer Behavior and
> Taxes',), ('Hunger, US, Poverty',), ('FERTILITY, Women',),
> ('Corporatism, Environment',), ('Economic Democracy, Corporate
> Farming',), ('Economic Democracy, Inspiration',), ('FEAR
> (Fearlessness)',), ('Federal budget, military spending, foreign
> cultural exchange programs',), ('Fish Farming',), ('Fish population,
> commercial fishing industry',), ('GMO, BT Cotton',), ('Food borne
> Illness, Water',), ('Food Charity',), ('Food Charity, Urban Farming',),
> ('Food Consumption, Luxury',), ('Food Cost, international',), ('Food
> Disposal, Waste',), ('Food stamps, eligibility for',), ('Food,
> expenditure on',), ('Foreign Aid',), ('Genetics, Food, Agriculture,
> International',), ('Global Policy, Bush Administration',), ('Global
> Trade, food',), ('Global Trade, free trade, clothing',),
> ('Globalization',), ('GMO, SACTO Protests',), ('GMO, Wheat, trade',),
> ('Happiness and income',), ('Health Care - Spending',), ('Hope',),
> ('Hope, inspirational quote',), ('Human Cloning',), ('Hunger',),
> ('Hunger, income',), ('IMF, Argentina',), ('IMF, failings',),
> ('Inequality',), ('INEQUALITY, GLOBALIZATION, POVERTY',), ('Inequality,
> Globalization, Latin America',), ('Inspiration',), ('Junk Food',),
> ('Junk Food, Soft Drinks',), ('Junk Food ,Children, Education,
> Media',), ('Junk Food, Education, Children, Nutrition',), ('Junk Food,
> Global, Coke',), (
Re: determining the bounds of a tuple returned from a database
very sorry, that was my error - len(result[0]) and len(result[1]) both
return 1 --
i think I'm misunderstanding what len() does - to me they appear to
have 2 or 3 elements, or at least be composed of a string of some
length.
I guess len() isn't the function i'm looking for then. How do I tell
how many strings, or how many bytes are in each dimension? so that I
can iterate through them.
Each entry in that list is a keyword - Alternately, is there any fast
way to parse that into a sorted list of distinct keywords.
very sorry for the error.
bests,
-rsr-
Fredrik Lundh wrote:
> ronrsr wrote:
>
> > it looks like the len() function is the one I want.
> >
> > for: len(result) - i get 248,
> >
> > but for len(result[0]) or len(result[1]) i always get 0.
>
> that's a bit surprising, because both items are tuples that contain
> exactly one item:
>
> >> (('Agricultural subsidies; Foreign aid',), ('Agriculture; Sustainable
> >> Agriculture - Support; Organic Agriculture; Pesticides, US, Childhood
> >> Development, Birth Defects; Toxic Chemicals',),
>
>
--
http://mail.python.org/mailman/listinfo/python-list
Why isn't SPLIT splitting my strings
I'm trying to break up the result tuple into keyword phrases. The
keyword phrases are separated by a ; -- the split function is not
working the way I believe it should be. Can anyone see what I"m doing
wrong?
bests,
-rsr-
print "newstring =", str(result[i][0])
print "just split", str(result[i][0]).split('; ()[]"')
zd.append(str(result[i][0]).split('; ()[]"'))
result= (('Agricultural subsidies; Foreign aid',), ('Agriculture;
Sustainable Agriculture - Support; Organic Agriculture; Pesticides, US,
Childhood Development, Birth Defects; Toxic Chemicals',),
('Antibiotics, Animals',), ('Agricultural Subsidies, Global Trade',),
('Agricultural Subsidies',), ('Biodiversity',), ('Citizen Activism',),
('Community Gardens',), ('Cooperatives',), ('Dieting',), ('Agriculture,
Cotton',), ('Agriculture, Global Trade',), ('Pesticides, Monsanto',),
('Agriculture, Seed',), ('Coffee, Hunger',), ('Pollution, Water,
Feedlots',), ('Food Prices',), ('Agriculture, Workers',), ('Animal
Feed, Corn, Pesticides',), ('Aquaculture',), ('Chemical Warfare',),
('Compost',), ('Debt',), ('Consumerism',), ('Fear',), ('Pesticides, US,
Childhood Development, Birth Defects',), ('Corporate Reform,
Personhood (Dem. Book)',), ('Corporate Reform, Personhood, Farming
(Dem. Book)',), ('Crime Rates, Legislation, Education',), ('Debt,
Credit Cards',), ('Democracy',), ('Population, World',), ('Income',),
('Democracy, Corporate
partial results:
string a = Agricultural subsidies; Foreign aid
newstring = Agricultural subsidies; Foreign aid
just split ['Agricultural subsidies; Foreign aid']
newstring = Agriculture; Sustainable Agriculture - Support; Organic
Agriculture; Pesticides, US, Childhood Development, Birth Defects;
Toxic Chemicals
just split ['Agriculture; Sustainable Agriculture - Support; Organic
Agriculture; Pesticides, US, Childhood Development, Birth Defects;
Toxic Chemicals']
newstring = Antibiotics, Animals
just split ['Antibiotics, Animals']
--
http://mail.python.org/mailman/listinfo/python-list
can't get cgi values
I'm having trouble extracting cgi parameters in my code - this is a web
application, so I only know the line that's causing the problem.
here's the info I know:
form = FieldStorage(None, None, [MiniFieldStorage('zid', '17'),
MiniFieldStorage('keywords', 'aAUA'), MiniFieldStorage('keywords',
'aBOS'), MiniFieldStorage('citation', 'The Earth Times Monthly,
April 2002\\r\\n \\r\\n \r\n '),
MiniFieldStorage('quotation', 'Farm support goes mainly to a relatively
small number of agri-businesses, many of them large corps. Yet these
subsidies are 6 times what rich countries provide in foreign aid to a
developing world that includes 5 billion people.\\r\\n \r\n
'), MiniFieldStorage('updatebutton', 'Update')])
form.has_key("citation") = True
fileHandle.write("here aer the haskeys");
fileHandle.write( str(form.has_key("citation")))
/* returns TRUE */
temp = str(form("citation").value)
/* python stops here,
form("citation appears to be undefined */
print (str(form("citation").value))
/* this doesn't work, either */
if form.has_key("keywords"): /*
neither does this */
keywords = str(form["keywords"].value)
else:
keywords = "k"
any ideas on what the problem is?
thank you so much.
-rsr-
--
http://mail.python.org/mailman/listinfo/python-list
Re: can't get cgi values
Thank you, all. that was very helpful, and did solve many of my
problems. I was addressing the dict with () rather than [].
I'm still having one problem, though -- extracting the keywords. NOw,
if you check the value for Form below, you'll see there is more than
one keyword entry. When I do: keywords = form["keywords"] - what sort
of data structure do I get back?
th anks so much again.
-rsr-
if form.has_key("keywords"):
keywords = str(form["keywords"].value)
else:
keywords = "k"
fileHandle.write("here comes keywords:")
fileHandle.write(str(keywords))
fileHandle.write("keyword info");
fileHandle.write(str(form.has_key("keywords")))
fileHandle.flush()
> here's the info I know:
>
> form = FieldStorage(None, None, [MiniFieldStorage('zid', '17'),
> MiniFieldStorage('keywords', 'aAUA'), MiniFieldStorage('keywords',
> 'aBOS'), MiniFieldStorage('citation', 'The Earth Times Monthly,
> April 2002\\r\\n \\r\\n \r\n '),
> MiniFieldStorage('quotation', 'Farm support goes mainly to a relatively
> small number of agri-businesses, many of them large corps. Yet these
> subsidies are 6 times what rich countries provide in foreign aid to a
> developing world that includes 5 billion people.\\r\\n \r\n
> '), MiniFieldStorage('updatebutton', 'Update')])
> form.has_key("citation") = True
>
>
--
http://mail.python.org/mailman/listinfo/python-list
Re: can't get cgi values
Thank you, all. that was very helpful, and did solve many of my
problems. I was addressing the dict with () rather than [].
I'm still having one problem, though -- extracting the keywords. NOw,
if you check the value for Form below, you'll see there is more than
one keyword entry. When I do: keywords = form["keywords"] - what sort
of data structure do I get back?
th anks so much again.
-rsr-
if form.has_key("keywords"):
keywords = str(form["keywords"].value)
else:
keywords = "k"
fileHandle.write("here comes keywords:")
fileHandle.write(str(keywords))
fileHandle.write("keyword info");
fileHandle.write(str(form.has_key("keywords")))
fileHandle.flush()
> here's the info I know:
>
> form = FieldStorage(None, None, [MiniFieldStorage('zid', '17'),
> MiniFieldStorage('keywords', 'aAUA'), MiniFieldStorage('keywords',
> 'aBOS'), MiniFieldStorage('citation', 'The Earth Times Monthly,
> April 2002\\r\\n \\r\\n \r\n '),
> MiniFieldStorage('quotation', 'Farm support goes mainly to a relatively
> small number of agri-businesses, many of them large corps. Yet these
> subsidies are 6 times what rich countries provide in foreign aid to a
> developing world that includes 5 billion people.\\r\\n \r\n
> '), MiniFieldStorage('updatebutton', 'Update')])
> form.has_key("citation") = True
>
>
--
http://mail.python.org/mailman/listinfo/python-list
splitting a long string into a list
I have a single long string - I'd like to split it into a list of unique keywords. Sadly, the database wasn't designed to do this, so I must do this in Python - I'm having some trouble using the .split() function, it doesn't seem to do what I want it to - any ideas? thanks very much for your help. r-sr- longstring = 'Agricultural subsidies; Foreign aidAgriculture; Sustainable Agriculture - Support; Organic Agriculture; Pesticides, US, Childhood Development, Birth Defects; Toxic ChemicalsAntibiotics, AnimalsAgricultural Subsidies, Global TradeAgricultural SubsidiesBiodiversityCitizen ActivismCommunity GardensCooperativesDietingAgriculture, CottonAgriculture, Global TradePesticides, MonsantoAgriculture, SeedCoffee, HungerPollution, Water, FeedlotsFood PricesAgriculture, WorkersAnimal Feed, Corn, PesticidesAquacultureChemical WarfareCompostDebtConsumerismFearPesticides, US, Childhood Development, Birth DefectsCorporate Reform, Personhood (Dem. Book)Corporate Reform, Personhood, Farming (Dem. Book)Crime Rates, Legislation, EducationDebt, Credit CardsDemocracyPopulation, WorldIncomeDemocracy, Corporate Personhood, Porter Township (Dem. Book)Disaster ReliefDwellings, SlumsEconomics, MexicoEconomy, LocalEducation, ProtestsEndangered Habitat, RainforestEndangered SpeciesEndangered Species, Extinctionantibiotics, livestockAgricultural subsidies; Foreign aid;Agriculture; Sustainable Agriculture - Support; Organic Agriculture; Pesticides, US, Childhood Development, Birth Defects; Toxic Chemicals;Antibiotics, Animals;Agricultural Subsidies, Global Trade;Agricultural Subsidies;Biodiversity;Citizen Activism;Community Gardens;Cooperatives;Dieting;Agriculture, Cotton;Agriculture, Global Trade;Pesticides, Monsanto;Agriculture, Seed;Coffee, Hunger;Pollution, Water, Feedlots;Food Prices;Agriculture, Workers;Animal Feed, Corn, Pesticides;Aquaculture;Chemical Warfare;Compost;Debt;Consumerism;Fear;Pesticides, US, Childhood Development, Birth Defects;Corporate Reform, Personhood (Dem. Book);Corporate Reform, Personhood, Farming (Dem. Book);Crime Rates, Legislation, Education;Debt, Credit Cards;Democracy;Population, World;Income;Democracy, Corporate Personhood, Porter Township (Dem. Book);Disaster Relief;Dwellings, Slums;Economics, Mexico;Economy, Local;Education, Protests;Endangered Habitat, Rainforest;Endangered Species;Endangered Species, Extinction;antibiotics, livestock;Pesticides, Water;Environment, Environmentalist;Food, Hunger, Agriculture, Aid, World, Development;Agriculture, Cotton Trade;Agriculture, Cotton, Africa;Environment, Energy;Fair Trade (Dem. Book);Farmland, Sprawl;Fast Food, Globalization, Mapping;depression, mental illness, mood disorders;Economic Democracy, Corporate Personhood;Brazil, citizen activism, hope, inspiration, labor issues;citizen activism, advice, hope;Pharmaceuticals, Medicine, Drugs;Community Investing;Environment, Consumer Waste Reduction, Consumer Behavior and Taxes;Hunger, US, Poverty;FERTILITY, Women;Agricultural subsidies; Foreign aid;Agriculture; Sustainable Agriculture - Support; Organic Agriculture; Pesticides, US, Childhood Development, Birth Defects; Toxic Chemicals;Antibiotics, Animals;Agricultural Subsidies, Global Trade;Agricultural Subsidies;Biodiversity;Citizen Activism;Community Gardens;Cooperatives;Dieting;Agricultural subsidies; Foreign aid;Agriculture; Sustainable Agriculture - Support; Organic Agriculture; Pesticides, US, Childhood Development, Birth Defects; Toxic Chemicals;Antibiotics, Animals;Agricultural Subsidies, Global Trade;Agricultural Subsidies;Biodiversity;Citizen Activism;Community Gardens;Cooperatives;Dieting;Agriculture, Cotton;Agriculture, Global Trade;Pesticides, Monsanto;Agriculture, Seed;Coffee, Hunger;Pollution, Water, Feedlots;Food Prices;Agriculture, Workers;Animal Feed, Corn, Pesticides;Aquaculture;Chemical Warfare;Compost;Debt;Consumerism;Fear;Pesticides, US, Childhood Development, Birth Defects;Corporate Reform, Personhood (Dem. Book);Corporate Reform, Personhood, Farming (Dem. Book);Crime Rates, Legislation, Education;Debt, Credit Cards;' -- http://mail.python.org/mailman/listinfo/python-list
splitting a long string into a list
I have a single long string - I'd like to split it into a list of unique keywords. Sadly, the database wasn't designed to do this, so I must do this in Python - I'm having some trouble using the .split() function, it doesn't seem to do what I want it to - any ideas? thanks very much for your help. r-sr- longstring = 'Agricultural subsidies; Foreign aidAgriculture; Sustainable Agriculture - Support; Organic Agriculture; Pesticides, US, Childhood Development, Birth Defects; Toxic ChemicalsAntibiotics, AnimalsAgricultural Subsidies, Global TradeAgricultural SubsidiesBiodiversityCitizen ActivismCommunity GardensCooperativesDietingAgriculture, CottonAgriculture, Global TradePesticides, MonsantoAgriculture, SeedCoffee, HungerPollution, Water, FeedlotsFood PricesAgriculture, WorkersAnimal Feed, Corn, PesticidesAquacultureChemical WarfareCompostDebtConsumerismFearPesticides, US, Childhood Development, Birth DefectsCorporate Reform, Personhood (Dem. Book)Corporate Reform, Personhood, Farming (Dem. Book)Crime Rates, Legislation, EducationDebt, Credit CardsDemocracyPopulation, WorldIncomeDemocracy, Corporate Personhood, Porter Township (Dem. Book)Disaster ReliefDwellings, SlumsEconomics, MexicoEconomy, LocalEducation, ProtestsEndangered Habitat, RainforestEndangered SpeciesEndangered Species, Extinctionantibiotics, livestockAgricultural subsidies; Foreign aid;Agriculture; Sustainable Agriculture - Support; Organic Agriculture; Pesticides, US, Childhood Development, Birth Defects; Toxic Chemicals;Antibiotics, Animals;Agricultural Subsidies, Global Trade;Agricultural Subsidies;Biodiversity;Citizen Activism;Community Gardens;Cooperatives;Dieting;Agriculture, Cotton;Agriculture, Global Trade;Pesticides, Monsanto;Agriculture, Seed;Coffee, Hunger;Pollution, Water, Feedlots;Food Prices;Agriculture, Workers;Animal Feed, Corn, Pesticides;Aquaculture;Chemical Warfare;Compost;Debt;Consumerism;Fear;Pesticides, US, Childhood Development, Birth Defects;Corporate Reform, Personhood (Dem. Book);Corporate Reform, Personhood, Farming (Dem. Book);Crime Rates, Legislation, Education;Debt, Credit Cards;Democracy;Population, World;Income;Democracy, Corporate Personhood, Porter Township (Dem. Book);Disaster Relief;Dwellings, Slums;Economics, Mexico;Economy, Local;Education, Protests;Endangered Habitat, Rainforest;Endangered Species;Endangered Species, Extinction;antibiotics, livestock;Pesticides, Water;Environment, Environmentalist;Food, Hunger, Agriculture, Aid, World, Development;Agriculture, Cotton Trade;Agriculture, Cotton, Africa;Environment, Energy;Fair Trade (Dem. Book);Farmland, Sprawl;Fast Food, Globalization, Mapping;depression, mental illness, mood disorders;Economic Democracy, Corporate Personhood;Brazil, citizen activism, hope, inspiration, labor issues;citizen activism, advice, hope;Pharmaceuticals, Medicine, Drugs;Community Investing;Environment, Consumer Waste Reduction, Consumer Behavior and Taxes;Hunger, US, Poverty;FERTILITY, Women;Agricultural subsidies; Foreign aid;Agriculture; Sustainable Agriculture - Support; Organic Agriculture; Pesticides, US, Childhood Development, Birth Defects; Toxic Chemicals;Antibiotics, Animals;Agricultural Subsidies, Global Trade;Agricultural Subsidies;Biodiversity;Citizen Activism;Community Gardens;Cooperatives;Dieting;Agricultural subsidies; Foreign aid;Agriculture; Sustainable Agriculture - Support; Organic Agriculture; Pesticides, US, Childhood Development, Birth Defects; Toxic Chemicals;Antibiotics, Animals;Agricultural Subsidies, Global Trade;Agricultural Subsidies;Biodiversity;Citizen Activism;Community Gardens;Cooperatives;Dieting;Agriculture, Cotton;Agriculture, Global Trade;Pesticides, Monsanto;Agriculture, Seed;Coffee, Hunger;Pollution, Water, Feedlots;Food Prices;Agriculture, Workers;Animal Feed, Corn, Pesticides;Aquaculture;Chemical Warfare;Compost;Debt;Consumerism;Fear;Pesticides, US, Childhood Development, Birth Defects;Corporate Reform, Personhood (Dem. Book);Corporate Reform, Personhood, Farming (Dem. Book);Crime Rates, Legislation, Education;Debt, Credit Cards;' -- http://mail.python.org/mailman/listinfo/python-list
Re: splitting a long string into a list
still having a heckuva time with this.
here's where it stand - the split function doesn't seem to work the way
i expect it to.
longkw1,type(longkw): Agricultural subsidies; Foreign
aid;Agriculture; Sustainable Agriculture - Support; Organic
Agriculture; Pesticides, US, Childhood Development, Birth Defects;
1
longkw.replace(',',';')
Agricultural subsidies; Foreign aid;Agriculture; Sustainable
Agriculture - Support; Organic Agriculture; Pesticides, US, Childhood
Development
kw = longkw.split("; ,")#kw is now a list of len 1
kw,typekw= ['Agricultural subsidies; Foreign aid;Agriculture;
Sustainable Agriculture - Support; Organic Agriculture; Pesticides, US,
Childhood Development, Birth Defects; Toxic Chemicals;Antibiotics,
Animals;Agricultural Subsidies
what I would like is to break the string into a list of the delimited
words, but have had no luck doing that - I thought split wuld do that,
but it doens't.
bests,
-rsr-
Robert Kern wrote:
> ronrsr wrote:
> > I have a single long string - I'd like to split it into a list of
> > unique keywords. Sadly, the database wasn't designed to do this, so I
> > must do this in Python - I'm having some trouble using the .split()
> > function, it doesn't seem to do what I want it to - any ideas?
>
> Did you follow the recommendations given to you the last time you asked this
> question? What did you try? What results do you want to get?
>
> --
> Robert Kern
>
> "I have come to believe that the whole world is an enigma, a harmless enigma
> that is made terrible by our own mad attempt to interpret it as though it had
> an underlying truth."
> -- Umberto Eco
--
http://mail.python.org/mailman/listinfo/python-list
dealing with special characters in Python and MySQL
I have an MySQL database called zingers. The structure is:
zid - integer, key, autoincrement
keyword - varchar
citation - text
quotation - text
the encoding and collation is utf-8
I am having trouble storing text, as typed in last two fields. Special
characters and punctuation all seem not to be stored and retrieved
correctly.
Special apostrophes and single quotes from Microsoft Word are causing a
special problem, even though I have ''ed all 's
error messages, when trying to save to database:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position
71: ordinal not in range(128)
args = ('ascii', "update zingers set keywords = ' aa;Action',
...ation = '\n\n ' where zid = 422", 71, 72, 'ordinal not
in range(128)')
encoding = 'ascii'
end = 72
object = "update zingers set keywords = ' aa;Action',
...ation = '\n\n ' where zid = 422"
reason = 'ordinal not in range(128)'
start = 71
I think my problem may be that I need to encode the string before
saving it in the databse. Can anyone point me in the right direction
here?
Thanks so much,
--
http://mail.python.org/mailman/listinfo/python-list
Re: dealing with special characters in Python and MySQL
structure for the DB: CREATE TABLE `zingers` ( `zid` int(9) unsigned NOT NULL auto_increment, `keywords` varchar(255) default NULL, `citation` text, `quotation` text, PRIMARY KEY (`zid`) ) ENGINE=MyISAM DEFAULT CHARSET=UTF8 AUTO_INCREMENT=422 ; code for storing to database: querystring = "update zingers set keywords = '%s', citation = '%s', quotation = %s' where zid = %d" % (keywords,citation,quotation,zid) ; cursor.execute(querystring) at this point, querystring = update zingers set keywords = ' aa;Action', citation = ' ', quotation = ' ' where zid = 422 where are an assortment of apostrophes and single quotes copied and pasted from a Word Document. > > And where is the actual code... What you've supplied doesn't show > how you are generating the SQL... > -- -- http://mail.python.org/mailman/listinfo/python-list
Re: dealing with special characters in Python and MySQL
> > are you passing in the strings as Unicode strings, or as something else? > if you're using something else, what have you done to tell the > database what it is? > not at all sure what I'm passing it as. The database default encoding is utf-8 the database collation is utf-8 the page encoding of the page is utf-8 what else do I have to tell the database? -- http://mail.python.org/mailman/listinfo/python-list
Re: dealing with special characters in Python and MySQL
version of python is 2.2 - -- http://mail.python.org/mailman/listinfo/python-list
Re: dealing with special characters in Python and MySQL
version of python is either 2.2 or 2.4 bests, -rsr- John Nagle wrote: > ronrsr wrote: -- http://mail.python.org/mailman/listinfo/python-list
Re: dealing with special characters in Python and MySQL
> >
> Try putting "use_unicode=True" in the MySQLdb "connect" call.
tried that, and also added charset="utf8" -
now, I can't do any string operations, I get the error msg:
descriptor 'lower' requires a 'str' object but received a 'unicode'
args = ("descriptor 'lower' requires a 'str' object but received
a 'unicode'",)
or similar, on every string operation.
many thanks,
-0rsr-
>
> See
>
> http://sourceforge.net/tracker/index.php?func=detail&aid=1559350&group_id=22307&atid=374932
>
> and look at other charset related bugs at
>
> http://sourceforge.net/tracker/?atid=374932&group_id=22307&func=browse
>
> Also note that MySQLdb didn't support this until recently, so check
> your version of MySQLdb. There still seem to be problems in that area.
>
> John Nagle
> Animats
--
http://mail.python.org/mailman/listinfo/python-list
Special Characters (Unicode, Ascii) in Python and MySQL
I have an MySQL database called zingers. The structure is:
zid - integer, key, autoincrement
keyword - varchar
citation - text
quotation - text
I am having trouble storing text, as typed in latter two fields.
Special characters and punctuation all seem not to be stored and
retrieved correctly.
Special apostrophes and single quotes from Microsoft Word are causing a
special problem, even though I have ''ed all 's
perhaps the encoding of the database itself should be different? it is
currenlty latin_swedish_ci
Input and output is through a browser.
I think my problem may be that I need to encode the string before
saving it in the databse. Can anyone point me in the right direction
here?
here's the error message:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position
95: ordinal not in range(128)
args = ('ascii', "update zingers set keywords =
'a;Action;b;Religi... \n \n \n ' where zid = 422", 95, 96, 'ordinal not
in range(128)')
encoding = 'ascii'
end = 96
object = "update zingers set keywords = 'a;Action;b;Religi... \n
\n \n ' where zid = 422"
reason = 'ordinal not in range(128)'
start = 95
the characters I am trying to add are startquote and endquote copied
and pasted from Microsoft Word.
Can anyone help me on this?
bests,
-rsr-
--
http://mail.python.org/mailman/listinfo/python-list
how to store and still search special characters in Python and MySql
I have an MySQL database called zingers. The structure is:
zid - integer, key, autoincrement
keyword - varchar
citation - text
quotation - text
I am having trouble storing text, as typed in latter two fields.
Special characters and punctuation all seem not to be stored and
retrieved correctly.
Special apostrophes and single quotes from Microsoft Word are causing
a
special problem, even though I have ''ed all 's
perhaps the encoding of the database itself should be different? it
is
currenlty latin_swedish_ci
Input and output is through a browser.
I think my problem may be that I need to encode the string before
saving it in the databse. Can anyone point me in the right direction
here?
here's the error message:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position
95: ordinal not in range(128)
args = ('ascii', "update zingers set keywords =
'a;Action;b;Religi... \n \n \n ' where zid = 422", 95, 96, 'ordinal
not
in range(128)')
encoding = 'ascii'
end = 96
object = "update zingers set keywords = 'a;Action;b;Religi...
\n
\n \n ' where zid = 422"
reason = 'ordinal not in range(128)'
start = 95
the characters I am trying to add are startquote and endquote copied
and pasted from Microsoft Word.
Can anyone help me on this?
bests,
-rsr-
--
http://mail.python.org/mailman/listinfo/python-list
