473,480 Members | 1,914 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Open and read a tab delimited file from html using python cgi

2 New Member
I am trying build a webpage which takes a large tab delimited .txt/.txt.gz file as user input from a form and using POST method(test.html) to send the data to cgi-bin directory to file.py which ideally should open the file read and put the data into a dataframe and do some analysis(which i have already wrttien in python and works well on terminal) on the data and send back the analysis results to a html page. That is where the problem i am facing, how to read the data in the file exactly with the separator. How to pass these data into a pandas dataframe with delimiter?

test.html
Expand|Select|Wrap|Line Numbers
  1. <form enctype = "multipart/form-data" action = "/cgi-bin/file.py" method = "post">
  2. <p>File: <input type = "file" name = "filename" /></p>
  3. <p><input type = "submit" value = "Upload" /></p>
  4. </form>
  5.  
file.py

Expand|Select|Wrap|Line Numbers
  1. import cgi, os
  2. import cgitb; cgitb.enable()
  3. import pandas as pd
  4.  
  5. form = cgi.FieldStorage()
  6.  
  7. fileitem = form['filename']
  8. if fileitem.file:
  9.     message=fileitem.file.read()
  10.  
  11. #df = pd.read_csv(message, sep='\t')
  12. #some code for analysis
  13. #some code for analysis
  14. #some code for analysis
  15.  
The 'message' if printed, prints the data without any separator in a single line, this should ideally passed into a pandas dataframe.

Thanks in advance for your time
Aug 21 '20 #1
2 2913
madankarmukta
308 Contributor
Please follow the standalone syntax for read_csv. Moreover engin might not be getting correct fs path. Can you please put here the fs message you are getting ?

Thanks.
Aug 23 '20 #2
luffy3not2
2 New Member
@madankarmukta Thank you for your response. fs message is working fine, its suppose open the file and read which its doing fine.
http://imgur.com/a/5ajd20b
But this print the entire data in a single line(please see the screenshot), i would like it to put in a table/dataframe.


Thank you

PS the image is the 'fs message' which prints the data in the file which is uploaded to test.html
Aug 24 '20 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1718
by: Danielsen Brian \(IFR Contractor External\) | last post by:
Does anyone know how to do file navigation between drives? I know how to navigate up and down within a drive (for example the C:\ drive), but I don't know how to change drives. I'm looking for...
13
5057
by: nitenmistry | last post by:
Hi, I'm creating a HTML report using Python and would like to import some tabular data which is in tab delimited format into the HTML page. The data needs to be displayed as a table within the...
4
3848
by: psbasha | last post by:
Hi, Is there any functions or classes available in Python to read xlsheet data? Thanks PSB
2
2046
by: myTesterFrench | last post by:
Hi All, Kindly, could you someone tell me how to read a page(any web site) using Python, what method to be used ? Paris
7
6663
by: Chi Yin Cheung | last post by:
Hi, Is there a way in python to output binary files? I need to python to write out a stream of 5 million floating point numbers, separated by some separator, but it seems that all python supports...
0
1168
by: Coaster | last post by:
I think I can but haven't seen an example. An app I inherited uses schema.ini and it forces all the files to have the same name because of the current format Format=Delimited(|) .... I'd...
2
2158
by: skulka3 | last post by:
Hello, I want to implement file downloads inside an authenticated web page, such that when a user clicks a link, the server side python code connects to a ftp server, downloads a relevant file...
1
1437
by: ruxhxNim | last post by:
Hi, I am new to webservice ,can anyone could help me out to know the code which help me to read xml file by using webservice. .XML file contains following type of tag (for eg.) <order> ...
1
6202
by: alivip | last post by:
How to brows and select a directory of file by using python TKinter like brows to find attachment in email but I can select not only file but whole directory any help
5
1401
by: PhilJunior | last post by:
I have just started learning Python and am trying to write a simple script to extract the IP address and the URL from a log file. The log file has around 600 entries and looks like this:...
0
7048
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6911
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6743
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5344
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
2999
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2988
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1303
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
564
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
185
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.