3 Replies - 2494 Views - Last Post: 14 December 2012 - 11:20 PM Rate Topic: -----

#1 adityamithal  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 92
  • Joined: 12-November 10

how do I write and read json obj to a file

Posted 14 December 2012 - 02:57 AM

down vote favorite


I am new to json & have limited knowledge of python.

I am trying to make a class which reads & write JSON object to file taking 1 argument of dictionary type.

class Student:

    def __init__(self,name,email,contact,skills,ug=None,pg=None):

        self.email=email
        self.contact=contact
        self.name=name
        self.skills=[skills]

        self.edu={"ug":[ug],"pg":[pg]} 

james=Student("James","j@j.com","+1 7789990007","Python","CS", "CS")

print vars(james)


I am getting invalid syntax error (I am using eclipse IDE & PyDev plugin) but the output is coming on http://codepad.org/5tRBiJKj

Now how do I write and read this to a file ?

Is This A Good Question/Topic? 0
  • +

Replies To: how do I write and read json obj to a file

#2 Tayacan  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 145
  • View blog
  • Posts: 275
  • Joined: 18-January 11

Re: how do I write and read json obj to a file

Posted 14 December 2012 - 07:10 AM

I don't get any errors when I try to run it (I just run it with python test.py). Can you post the error you're getting (or maybe a screenshot, if it's from your IDE)?
Was This Post Helpful? 0
  • +
  • -

#3 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6066
  • View blog
  • Posts: 23,526
  • Joined: 23-August 08

Re: how do I write and read json obj to a file

Posted 14 December 2012 - 08:30 AM

Obvious cross-post is obvious.
Was This Post Helpful? 0
  • +
  • -

#4 adityamithal  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 92
  • Joined: 12-November 10

Re: how do I write and read json obj to a file

Posted 14 December 2012 - 11:20 PM

View PostJackOfAllTrades, on 14 December 2012 - 08:30 AM, said:



I have made further progress but still not getting them in the file. Please help if you can
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1