Reading JSON with Python Dicts [closed] - python

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have no idea if this is possible, I want to know if it's possible to use Python dicts to read JSON, I have crawled the web for answers, but I don't think anyone has had the same idea, or it's just not possible. It may be a confusing question, But, here it goes!
I have a Python Dict as;
dict1 = {"3.8.1":"data[0]['3.8.1']","3.8":"data[1]['3.8']"}
As you can see, It'd get the json request string from the first dict with the found wordpress version number
dict1["3.8.1"]
would return the required next section to read from the loaded JSON file
I didn't "think" it was possible, but I thought I'd ask. As you can see in the above dict, It contains a way I could possibly request from the loaded JSON.
Anyway, any input, or other ways I could do it would be great, Thanks.

Are you looking for exec()?
exec("myvar = " + dict1["3.8.1"])

Related

Need help on program that uses facebook/instagram info [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
A client wants to have information about public instagram/facebook profiles (photos/videos published, total likes/comments) from a period of time. How do I go about doing this?
I found out that some of that information is available in the website source code, but how do I use that information? Also is there any sites/services that does that already? The only ones I found only go as back as a few weeks, or only procress future posts.
I thought about automatizing the process with python, is it a good idea?
I'm new in programming, so any help is aprecciated.
As far as I know Instagram is trying to limit as much as possible bot activities, I'm not sure about Facebook though.
You can definitely try to webscrape (using python or other tools) the information you need but if things don't work, it may not be your fault.

it possible to generate the rss feed from a website that didnt provide rss [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I want to know if it's possible to use Python or any other way to generate an RSS feed for a website, if the site does not provide RSS feeds.
Are there any examples?
Yes, if I would build something like that I would design it like this.
Write a Flask server which would handle request.
On every request download data from the target website with bs4.
Transform the data to XML output according to RSS format.
It's a bit more than just short code, but nothing very hard.

What's the difference between a hash table and a Python dictionary? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I am starting to learn about the hash table data structure in C, and I've noticed (if I understand the concept correctly) that hash tables are awfully similar to python dictionaries. If I am incorrect and they are two completely different things, could someone explain to me what a hash table is without getting too technical? Thanks.
There is not really any difference between them. That's why python's dicts don't support duplicates. That is also why python has the function hash which python's dictionaries use by default.

change the content of py file [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I have a python file which contain a dictionary and one more file which importing the file with the dictionary.
I need to change the actual value of keys, I mean permanently - not by importing and editing for the code,
How can I accomplish that ?
There is a very good reason why programmers have learned over the years not to modify the source of their programs under program control. It results in a mess, particularly when multiple people try to use the same program at the same time, and means that you can't effectively keep your code under source control.
It would be much better to use some way of storing the keys and values outside the program. Depending on the types of key that could be a shelve, a relational database or a number of other things. If it varies, data should not be built into your program's source.
Use pickle
import pickle
myDict = {"foo": "bar", "spam": "eggs"}
pickle.dump(myDict, "myFile.py") # Stores object in a file
dictFromFile = pickle.load("myFile.py") # Retrieves object from files
print dictFromFile["spam"] # Prints eggs

Should I use a ConfigParser directly in my code? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 1 year ago.
Improve this question
I hope there is a 'right' answer to this:
When using ConfigParser to manage default values in a .cfg or .ini file, should I copy everything I need to program variables and copy them back out on exit, or should I use the config.get(section, option) directly in my program as needed?
This is really a matter of opinion, but my advice is to have the values out of the config relatively quickly. The code that deals with data input and the layer that deals with the actual processing should be modular enough that you can change your data source by just feeding in data from a different source. (Coupling and Cohesion)
You'll have to use your own judgement to make the call as to where to draw the line, but as a guide: if you're setting the config as a global variable and reading from there or constantly throwing it around as an argument, you're doing it wrong.

Categories