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 6 years ago.
Improve this question
So i have a program where the user enters in a few details e.g name, place etc. However, when i collect these details, they are all assigned to the variable name that i gave to the input collector (e.g input =). But i need to process these variables into a specific order (its a bibliography generator fyi). However i need to assign each of the instances of inputs into different variables without having basically the same code over and over again, but i couldn't think of a way to do that.
Help would be much appreciated.
Here is how I solve that problem in the past:
1) Store the data in an ordered dictionary.
2) Store the data in an object and use a function that returns the data in the order specified.
Related
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 10 months ago.
Improve this question
If we talk about resources, memory, legibility what would be better between:
Create all the instances at the beginning of a method? (left side of the screenshot)
Create the instances as we need to use them? (right side of the screenshot)
Do you have any documentation that says which is better? I searched in the Python documentation but found nothing.
Well in python creating instances is creating instances, regardless of where you do such, the same amount of instances will be created taking the same amount of storage space.
If you're looking into memory conservation I'd recommend using the del operator when instances are no longer needed.
Other than that this is totally just up to personal preference, and how you'd like to format your code.
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
My api needs to be something like this:
api/search_fields=country_name,region,city,pincode,dma&exclude=false,true,true,false&country_name=india,pakistan®ion=tamil nadu,jammu kashmir,&city=ahmedabad&pincode=112&dma=1
Means if country_name is excluded their correspoding region,city,pincode,dma will not come in result.Same way if region is exluded city,pincode,dma will not come in results of which all countries are excluded and which all regions are excluded.
How can i write mysql template in python for all these.
Although the question is very wide, I will try to answer.
The general idea is checking what the user has specified in the request and then hide absent columns in the output. We call it a view logic. You can take care of it in Controller or in Template directly.
Probably, it does not help you too much, but I cannot answer another way so broad question.
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.
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 2 years ago.
Improve this question
So there is this c++ code I am migrating to python and I am stuck at one point where I need to write a structure in python, I have handled that by using class. But the difficulty here is the structures has pointers as members and I don't know how to proceed with this
typedef struct {
string_t filename;
string_t version;
node_list_t *node_list;
valtable_list_t *valtable_list;
message_list_t *message_list;
envvar_list_t *envvar_list;
attribute_rel_list_t *attribute_rel_list;
attribute_definition_list_t *attribute_definition_list;
signal_group_list_t *signal_group_list;
network_t *network;
} dbc_t;
In the above code all the data types are type definitions and I am stuck with the pointers on the RHS.
Can someone help me in handling this ?
Thanks! :)
Edit: Retracting my statements as that caused confusion.
All you need to do is assign the variable directly to the member as variables act as reference in case of objects.
You can read more about how python is pass by value for all variables, but how that means its pass by reference for objects here.
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.