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 7809643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:30:15+00:00 2026-06-02T03:30:15+00:00

My project has a bunch of csv files that may or may not be

  • 0

My project has a bunch of csv files that may or may not be called based on user input. I’d like to store these files in a subdirectory to keep my project folder uncluttered. I’m utterly confused as to how to do this. Most of the resources I’ve dug up involve importing a module or package from a subdirectory rather than a basic data file.

The line of code that imports my csv currently looks like:

target_doc = csv.reader(open('sample.csv', 'rU'), delimiter=",", quotechar='|')

I’m assuming a solution will involve setting up a path variable, using import os and import sys, and perhaps splitting this line multiple parts?

  • 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-02T03:30:16+00:00Added an answer on June 2, 2026 at 3:30 am

    You can open files by file path. Just use open('/path/to/file').

    Importing is only necessary for modules and packages – Python source code.

    The only real notes here are to use os.path.join() where joining paths for good compatibility across different operating systems and filesystems. The rest of the os.path module is also worth a look wherever files are involved. Another common trap with windows paths is that using backslashes escape characters, so you must escape your backslashes ("some\\file") – an ugly option, use raw strings (r"some\file"), use forward slashes (Python will actually handle this automatically), or – the best option, pass your path as arguments to the aforementioned os.path.join().

    It may also be worth noting that using the with statement would improve your code.

    e.g:

    with open(os.path.join("path", "to", "file.csv"), 'rU') as file:
        target_doc = csv.reader(file, delimiter=",", quotechar='|')
        ...
    

    Using with ensures your file gets closed – even if exceptions occur.

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

Sidebar

Related Questions

I have a project, let's call it BASE, that has a bunch of .CSV
My project has a C++ library that I want to allow the user to
While working on a project that will store a whole bunch of (completely different)
I have a big C++ project that has about hundred source files that are
I have a RSS/Atom document that has a bunch of <entry> <title>project name</title> <link
My Project has 2 java files (A.java and B.java in same package). A.java uses
My project has a file foo that I've been using and checking in with
I have a project that has existed for quite a while, and I recently
I need to create a project that has a web frontend to manage synchronous
I have created a WiX project that installs a bunch of different EXEs 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.