csv

Python: pass arguments to a script

懵懂的女人 提交于 2021-02-20 04:12:44
问题 I have a working code to print random lines from a csv column. #!/usr/bin/python import csv import random **col**=2 with open('<filename>','r') as f: reader=csv.reader(f) data=[row[col] for row in reader] from random import shuffle shuffle(data) print '\n'.join(data[:**100**]) f.close(); I want to paramaterize this script. by passing , position (col) & sample (e.g. 100 values) I am unable to find a decent tutorial which would explain this. any thoughts ? 回答1: You can use the sys module like

Django Wagtail CSV and photo “upload” - management command

送分小仙女□ 提交于 2021-02-20 02:21:51
问题 I am working on a django/wagtail management command (let's call it "file_upload") that does roughly the following: take "csv" argument, which is a full path to a CSV file. parse and open the result using csv for each row, create and save a custom Wagtail Image model object (inheriting from AbstractImage , with a few extra CharField that I do not think prevent me from doing what I want to do) The (currently simplified) CSV looks like this: 1.jpg,Title 1 2.jpg,Title 2 Does not complicated at

Django Wagtail CSV and photo “upload” - management command

戏子无情 提交于 2021-02-20 02:20:48
问题 I am working on a django/wagtail management command (let's call it "file_upload") that does roughly the following: take "csv" argument, which is a full path to a CSV file. parse and open the result using csv for each row, create and save a custom Wagtail Image model object (inheriting from AbstractImage , with a few extra CharField that I do not think prevent me from doing what I want to do) The (currently simplified) CSV looks like this: 1.jpg,Title 1 2.jpg,Title 2 Does not complicated at

Django Wagtail CSV and photo “upload” - management command

こ雲淡風輕ζ 提交于 2021-02-20 02:17:19
问题 I am working on a django/wagtail management command (let's call it "file_upload") that does roughly the following: take "csv" argument, which is a full path to a CSV file. parse and open the result using csv for each row, create and save a custom Wagtail Image model object (inheriting from AbstractImage , with a few extra CharField that I do not think prevent me from doing what I want to do) The (currently simplified) CSV looks like this: 1.jpg,Title 1 2.jpg,Title 2 Does not complicated at

Using Powershell environmental variables as strings when outputting files

三世轮回 提交于 2021-02-19 18:50:43
问题 I am using Get-WindowsAutopilotInfo to generate a computer's serial number and a hash code and export that info as a CSV. Here is the code I usually use: new-item "c:\Autopilot_Export" -type directory -force Set-Location "C:\Autopilot_Export" Get-WindowsAutopilotInfo.ps1 -OutputFile Autopilot_CSV.csv Robocopy C:\Autopilot_Export \\Zapp\pc\Hash_Exports /copyall This outputs a CSV file named "Autopilot_CSV.csv" to the C:\Autopilot_Export directory and then Robocopy copies it to the Network

Export large CSV file using laravel

我怕爱的太早我们不能终老 提交于 2021-02-19 08:37:27
问题 I have to export 600k database rows with a belongsTo relationship between two tables to a csv file using a queued job in laravel 5.2, it works fine when I do not include the information from the second table, but it reaches memory limit or timeout I guess (there is no error on the output, the job just stops and the file blocks at ~8MB) when I include the second table. Here is my handle function from my job : public function handle() { $request = $this->request; $ts = Carbon::now()->timestamp;

Array to CSV file for vertical layout and failed to put the header row

会有一股神秘感。 提交于 2021-02-19 07:45:07
问题 I have a problem to create a horizontal layout for the csv here is an array which I have convert it to json-format {"datetime":["2000-01-01","2000-01-02","2000-01-03","2000-01-04","2000-01-05","2000-01-06","2000-01-07","2000-01-08","2000-01-09","2000-01-10","2000-01-11","2000-01-12","2000-01-13","2000-01-14","2000-01-15","2000-01-16","2000-01-17","2000-01-18","2000-01-19","2000-01-20","2000-01-21","2000-01-22","2000-01-23","2000-01-24","2000-01-25","2000-01-26","2000-01-27","2000-01-28","2000

What are the efficient ways to parse / process huge JSON files in Python? [closed]

我是研究僧i 提交于 2021-02-19 07:35:07
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago . Improve this question For my project I have to parse two big JSON files, one is 19.7 GB and another 66.3 GB. The structure of the JSON data is too complex. First Level Dictionary and again in 2nd level there might be List or Dictionary. These are all Network Log files, I have to

What are the efficient ways to parse / process huge JSON files in Python? [closed]

戏子无情 提交于 2021-02-19 07:35:02
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago . Improve this question For my project I have to parse two big JSON files, one is 19.7 GB and another 66.3 GB. The structure of the JSON data is too complex. First Level Dictionary and again in 2nd level there might be List or Dictionary. These are all Network Log files, I have to

Write to csv file

我的未来我决定 提交于 2021-02-19 06:45:06
问题 I need some contents to be written in csv format to a file using ansible shell: ps -ef | grep java | awk '{print $1}' register: username shell: ps -ef | grep java | awk '{print $2}' register: id The output for username will be similar to : root admin test_admin The output for id will be similar to: 1232 4343 2233 so I want this to be written to a csv file as root,1232 admin,4343 test_admin,2233 Please suggest. 回答1: You can use a combination of the zip, map and join filters to achieve your