Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8282495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:23:25+00:00 2026-06-08T10:23:25+00:00

In the following function, i upload a file from a template and pass it

  • 0

In the following function, i upload a file from a template and pass it to the following function.But the data gets crippled if there is a \n or \t(This is a tab separated file).

1.If there is a \n or some special characters it stores the data in the next row.How to avoid this .

2.data is not None or data != “” still stores a null value

def save_csv(csv_file,cnt):
 ret = 1
 arr = []
 try:
  flag = 0
  f = open(csv_file)
  for l in f:
     if flag == 0:
        flag += 1
        continue
     parts = l.split("\t")
     counter = 1
     if(len(parts) > 6):
        ret = 2
     else:
        taggeddata = Taggeddata()
        for data in parts:
           data = str(data.strip())
           if counter == 1 and (data is not None or data != ""):
              taggeddata.field1 = data
           elif counter == 2 and (data is not None or data != ""):
              taggeddata.field2 = data
           elif counter == 3 and (data is not None or data != ""):
              taggeddata.field3 = data
           elif counter == 4 and (data is not None or data != ""):
              taggeddata.field4 = data
           elif counter == 5 and (data is not None or data != ""):
              taggeddata.field5 = data
           elif counter == 6 and (data is not None or data != ""):
              taggeddata.field6 = data
           counter += 1
        taggeddata.content_id = cnt.id
        taggeddata.save()
        arr.append(taggeddata)
  return ret
except:
  write_exception("Error while processing data and storing")
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T10:23:26+00:00Added an answer on June 8, 2026 at 10:23 am
    1. Use the stdlib’s csv module to parse your text, it will be much better at it.

    2. Your expression data is not None or data != "" is always true, you meant data is not None and data != "". Note that you can simplify this to just elif counter == 3 and data:

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have download the code for OpenFileDialog (File Upload function) from Silverlight tutorials website.
Possible Duplicate: django file upload from json Hi am using the following ajax upload
All, I know that there is this question already out there: jquery file upload
I use the following function to rename thumbnails. For example, if I upload a
The following function rewrites urls from news and product titles that contain all sorts
The following function is designed to check whether this row in this tables exists.
I am asking the user to upload a file, through the following form making
Code successfully upload file when I remove jquery script codes and submit. But with
The following method of course works, but after a certain number of uploads (this
I'm trying to upload a file using AJAX, process data in the file and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.