2
Trying to populate a table in Django: unsupported operand type(s) for %: 'table' and 'tuple'
Post Body
This is for a python script where I am populating my django table using data I have scraped (on line 4).
For a full snapshot of my populate_players.py and models.py files see: https://gist.github.com/fynnab/cdadbe8f5b13269a81e8
The snippet of my code where I'm doing something wrong is:
# Getting an instance of clubs so I can insert this foreignkey into my models
club1 = "Arsenal"
club2 = clubs.objects.get(name = club1);
def add_players(name, position, born, nationality, club, active=True):
# run the script per club
p = players.objects.get_or_create(name=name, position=position, born=born, nationality=nationality, club=club)
return p
Arsenal = json.load(urllib2.urlopen("http://api.football-data.org/alpha/teams/57/players"))
for team in Arsenal['players']:
name1 = team['name']
position1 = team['position']
born1 = team['dateOfBirth']
nationality1 = team['nationality']
def populate():
add_players(
name ='%s',
position = '%s',
born = '%d',
nationality = '%s',
club = club2
% (name1, position1, born1, nationality1)
)
And my traceback. 'clubs' is the name of one of my tables in django and a foreign key in my players model. So the problem must be related to that.
Starting player population script...
Traceback (most recent call last):
File "populate_players.py", line 50, in <module>
populate()
File "populate_players.py", line 41, in populate
% (name1, position1, born1, nationality1)
TypeError: unsupported operand type(s) for %: 'clubs' and 'tuple'
(test_env) C:\Users\WriteCode\test_env\epl>
Author
Account Strength
100%
Account Age
12 years
Verified Email
Yes
Verified Flair
No
Total Karma
14,533
Link Karma
10,604
Comment Karma
3,929
Profile updated: 1 week ago
Posts updated: 10 months ago
Subreddit
Post Details
We try to extract some basic information from the post title. This is not
always successful or accurate, please use your best judgement and compare
these values to the post title and body for confirmation.
- Posted
- 9 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/learnpython...