Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Request for simple code
#1
Dear Users,

I would like to request some help in some research work. My goal is to write data from an xls file to a text file (the text file is generated by a simulation software).

We will call the text file F1 and the xls F2.

F1 contains the parameter of the simulation, for example:
//parameters
weight = 2
area = 3
length = 4

F2 contains the same information with for example "weight" in a cell and the value in the next one.

I would like that the code takes/reads the value from the xls and update the corresponding line of the txt with it and finally saves the updated txt file with another name.

My point here is to get a base code on which I can work and adapt according to my case study.

I thank in advance for your help,

Regards
Quote
#2
Hello and welcome to the forum.
What have you tried? We are glad to help, but we are reluctant to do your work for you. Unless you want to move this thread in the [paid] jobs section....
Please, post your code (in code tags) and ask specific questions. Don't forget to include the full traceback (in error tags) if you get one.
Quote
#3
What are the necessary functions I can build my code with?
Open a file, read or search in a file, replace string characters, locate characters in a text file.
Quote
#4
Here is outline of the steps:
1. Open the xls file and read it into memory, storing data in some data structure (e.g. dict) with key:value pairs that makes it easy to retrieve specific value, given the key
2. Open the text file for reading, open another text file for writing.
3. iterate over the original file, line by line. For each line (it's a str) replace parameter value with the one from the data structure created from the excel file and write the new line in the new text file (the one open for writing).

for basic introduction on working with files read our tutorial  https://python-forum.io/Thread-Basic-Files
for working with excel files there are plenty of options, but in any case you will need to install external package. Also it depends if it is xls or xlsx file. Some options are listed here http://www.python-excel.org/ i.e. look openpyxl and xlrd. There are also other packages like pyexcel, xlwings, etc.
If you can swap the excel file with csv file (i.e. save the excel file as csv) you can use the built in csv module and will not need to install external packages.
There is also option to use heavy packages like pandas and numpy that work with both text/csv and excel files, but for task like this it's overkill.

Now, start working on your code and ask specific questions :-)
BTW, it took me more time to write this post than the actual code, but anyway... :-)
sparkz_alot likes this post
Quote
#5
Dear Buran,

Thank you for your feedback.

As coding is not my core specialty, I came on this forum to find help, as I am not asking for a NASA code. It seems that this is more a place for business (paid request).

Myself I am glad to people with what I know without asking how much they can pay. I apologize for using your time.

You said it yourself: it took me more time to write this post than the actual code.

Take care,
Quote
#6
(Oct-20-2017, 11:29 AM)CuriousMind Wrote: As coding is not my core specialty, I came on this forum to find help, as I am not asking for a NASA code. It seems that this is more a place for business (paid request). Myself I am glad to people with what I know without asking how much they can pay. I apologize for using your time.

I never asked you to pay anything. As a moderator I just asked you if you want to move the thread to the appropriate sub-section. In addition I outlined the necessary steps and provided links to additional materials - tutorials, possible external libraries, etc. That is everything, short of actually writing the code.

You said that your goal is to get a base code on which you can work and adapt according to your case study. That is why I assume you have at least basic knowledge or want to learn how to code.
micseydel likes this post
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Newbie at using python and tensorflow getting error when running simple code FeatherineAu 0 2,022 Sep-28-2018, 02:09 PM
Last Post: FeatherineAu

Forum Jump:


Users browsing this thread: 1 Guest(s)