Python Forum
[Python Basics] How To Handle Data For This Project?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Python Basics] How To Handle Data For This Project?
#1
Hey guys,

I'm working on a project where I need to post data to a website.

I need to manage multiple sets of the following data:
  • Title
  • Description (multi-line string)
  • Price

I'm thinking about making one folder per set of data so for example:

Folder 1
Title.txt
Description.txt
Price.txt

Folder 2
Title.txt
Description.txt
Price.txt

Folder 3
Title.txt
Description.txt
Price.txt

There will be an image or two in each folder.

I might go with a single CSV file vs. the text files, I want to keep it super simple though.

What's an efficient and uncomplicated way to store this data in Python where I can easily loop through it to pull what I need?

PS - I don't need any code, just the knowledge of how to move forward. Cheers!
Reply
#2
I would just use JSON. Its basically a python dictionary. Then you can load it and loop through it quite easy. You can also look at the database as well as change it on the fly if needed since its human readable.
Recommended Tutorials:
Reply
#3
(Nov-16-2017, 07:48 PM)metulburr Wrote: I would just use JSON. Its basically a python dictionary. Then you can load it and loop through it quite easy. You can also look at the database as well as change it on the fly if needed since its human readable.

Can I process plain text with JSON? From what I saw looking at some tutorials, it looks like the text needs to have the JSON dictionary format to be processed, is that right?

[Image: tENaujVuT-a3OAuti1cr1w.png]

Ideally I'd like to avoid having any syntax in the text files because the bot will be used by non-tech users.

I stumbled across an objects / classes tutorial that seems like it might work. Is that a viable alternative?
Reply
#4
I figured out how to convert CSV to JSON:

json.dumps(list(csv.reader(open('file.csv'))))
And .txt file to JSON:

(json.dumps(list(open('file.txt')))
I don't understand how I would have a multi-line string of text since it can't be done in a CSV cell, and if I do multiple lines in a .txt file JSON parses those lines as separate values.

Do I need to merge the lines within Python?


~~~~~~~~~~~~~~~
UPDATE: I think I figured it out, thanks again for putting me onto JSON, good call!
~~~~~~~~~~~~~~~
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Is it possible to extract 1 or 2 bits of data from MS project files? cubangt 8 1,059 Feb-16-2024, 12:02 AM
Last Post: deanhystad
  How do I handle escape character in parameter arguments in Python? JKR 6 1,159 Sep-12-2023, 03:00 AM
Last Post: Apoed2023
  Learned Python Basics, what now? muzikman 20 6,055 Oct-11-2021, 01:34 AM
Last Post: Underscore
  CPC File Format (Cartesian Perceptual Compression) - Can Python Convert / Handle Them PSKrieger 2 2,472 Nov-11-2020, 02:57 PM
Last Post: PSKrieger
  PYserial basics? bako 10 5,118 Apr-26-2020, 09:15 PM
Last Post: bowlofred
  [split] Debugging scripts basics tultalk 5 3,083 Apr-25-2020, 01:02 AM
Last Post: menator01
  Debugging scripts basics bako 8 3,506 Apr-24-2020, 06:18 AM
Last Post: Larz60+
  Create sensor data for a IoT project georgelza 9 5,882 Dec-20-2019, 06:19 PM
Last Post: georgelza
  Project, Reading Data from a spreadsheet. Error message!! Shafla 1 5,216 Sep-27-2019, 10:44 AM
Last Post: buran
  random behavriour when handle process termination signal in Python hamzeah 2 2,043 Jul-31-2019, 07:32 AM
Last Post: hamzeah

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020