question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Write mode for topen

See original GitHub issue

Overview

It’s a long shot but eventually I suppose it could be implemented.

Having a task to write some tabular data to the filesystem is casual. With all the boilerplate code to support py2/3, csv verbose interface etc - it’s a little bit annoying.

Analysis

Interface could be:

with topen('table.csv', mode='w') as table:
    table.write(data)

Implementation could be:

  • topen returns ReadTable or WriteTable regarding to the mode='r/w'
  • for writing there will be new modules like Formatter (anti-parser) and Writer (anti-loader) with the same modular arhictecture for different targets and formats.

So we will be able to have memory lean things like:

with (topen('http://site.com/source.xls') as source, 
      topen('target.csv', mode='w') as target):
    target.write(source)

Or even with something like tcopy helper:

tcopy(data, 'target.csv')
tcopy('http://site.com/source.xls', 'target.csv')

Tasks

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
rollcommented, Aug 7, 2016

@pwalsh Just lazy example) We use streams here) So it should be memory lean.

After we will finish it my idea to create example like loading 1GB xls from the web and saving it to csv file with memory profiler showing we don’t use memory)

0reactions
pwalshcommented, Aug 7, 2016

@roll ok, if that is the internal design. In your examples above, would the writing require the file contents to be loaded to memory? The API description looks like yes, but that would be a mistake IMHO.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to open a file for both reading and writing? - Stack Overflow
'r+' opens the file for both reading and writing. On Windows, 'b' appended to the mode opens the file in binary mode, so...
Read more >
How to open a file in read and write mode with Python?
To open files in read/write mode, specify 'w+' as the mode. For example, f = open('my_file.txt', 'w+') file_content = f.read() ...
Read more >
fopen() for an existing file in write mode - GeeksforGeeks
In C, fopen() is used to open a file in different modes. To open a file in write mode, “w” is specified. When...
Read more >
Python - Read and Write Files - TutorialsTeacher
Opening a file with "w" mode or "a" mode can only be written into and cannot be read from. Similarly "r" mode allows...
Read more >
File Handling in Python: Create, Open, Append, Read, Write
Write mode creates a file for writing content and places the pointer at the start. If the file exists, write truncates (clears) any...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found