Programming :: Python - Get Text File Data Into An Array On Python?

Nov 30, 2009

I've already used line split stuff to transform my data into something like this in a text file:

Code:

['1', '1', '3', '20.7505207']
['2', '1', '3', '23.0488319']
['3', '1', '3', '-1.5768747']
['4', '1', '3', '-26.4772491']

[code]....

How can I get this on a python program so I can manipulate it as an array?

View 3 Replies


ADVERTISEMENT

Programming :: Saving File Data Using Python In An Embedded System In An Safe And Fast Way?

Apr 19, 2011

I am developing a program in a system where the Linux does not take care of the sync command automatically. So I have to run it from my application always I save some data in the disk, which in my case is a 2GB sdcard. It is true that I can make the operation system takes care of the syncronization, using a proper mount option, but in this case the programm's performance drops drastically. In particular I use the shelve module from Python to save data that comes from a socket/TCP connection and I have to deal with the potencial risk of the system being turned off suddenly Initially I wrote something like that to save data using shelve:

Code:

def saveData(vo)
fd = shelve.open( 'fileName' , 'c')
fd[ key ] = vo
fd.close()
os.system("sync")

But that takes too much time to save the data. Note that I use the sync from the OS every time I close a file to prevent data corruption in the case of the "computer" being turned off with data even in the buffer. To improve the performance I made something like that:

Code:

def saveListData( list )
fd = shelve.open('file_name', 'c')
for itemVo in list:
fd[itemVo.key] = itemVo
fd.close()
os.system("sync")

Thus, first I saved an amount of objects in a list then I open the file and save the objects. In this way I have to open the file just one time to save a lot of objects.However I would like to know if adding a lot of objects before closing the file would increase the risk of data corruption.I known that turning off the system after fd.close() and before os.sync may cause problems. But what about turning off the system after

Code:

fd = shelve.open('file_name', 'c')

but before fd.close()?

View 7 Replies View Related

Programming :: Multi Dimensional (3 Array) In Python

Jul 28, 2010

I do a lot of scientific work - mainly in C/C++ but want to do some of the calcs in python, however I am finding it a problem with the lack of dimensionality. I frequency have a list of n particles and a multi-dim array for each particle and want to be able to access directly any component with ease. How best to go about this...

my prop = [n][x][y][z]

I might need a particular value and then to update that. I do not want to have to deal with lists etc etc as this feels rather cumbersome, adding, removing etc. There must be an easy way.

View 2 Replies View Related

Programming :: Make Python Programs Run Without Entering The Command Python?

Mar 22, 2009

I want to be able to do

sudo ./program.py

instead of always having to do

sudo python program.py

What do I need to change?

View 5 Replies View Related

Programming :: Python - Parsing Data In Chunks / Sections?

Nov 5, 2010

As a curious side project I'm playing with mzXML data(an xml format for holding mass spec data). A typical scan can be quite large, even up into GB size. I'm wondering how would one go about parsing an xml file in sections, one section at a time. The idea being if the computer doesn't have enough memory to load up the entire data file, work on chunks of it at a time.

View 3 Replies View Related

Ubuntu :: Python : Remove Some Lines From A Text File?

Sep 6, 2010

I am creating my own address book Python program and I want to create a nction that removes some specified entries. The code looks like this now.

Code:
def remove():
delentry= raw_input('Enter the entry name to delete: ')

[code]...

View 1 Replies View Related

Programming :: Python 2.x - Represent The Same In Python 3.x

Mar 4, 2010

I have a function definition in a Python 2.x script which take a tuple as one of its arguments, but 2to3 has no answers nor any of my searching on how to represent the same in Python 3.x

Code:

def blah(self, (string1, string2))

View 4 Replies View Related

Programming :: Take A List From A File And Use It In A For Loop In Python?

May 11, 2009

so far I have this

list = open('list.txt')
for x in list:
list.read(x)

View 3 Replies View Related

Programming :: Parse The File Correctly With Python

Nov 27, 2010

I'm currently curios with my python program which the basic goal is to parse the character in mytestfile;let's see the code

Code:
f=open('/home/andrewraharjo/Desktop/snort.log','r')
j=f.read()

[code]...

View 3 Replies View Related

Programming :: Python Bluetooth File Exchange

Feb 13, 2011

I've run into a little problem, for which I seem to be unable to find an answer. The concept is the following: one machine runs a python script which advertises itself as 'OBEX File Transfer' and receives incoming data, using the Lightblue python module. The script itself is slightly different, but here's an example which effectively works in the same way:

[Code]....

print "Saved received file to MyFile.txt!" This works fine, though I would like to retain the original filename that is being sent to the machine, instead of overwriting a fixed file. Generating a new name wouldn't be such a problem, if I could get the MIME type or filename which is (presumably) being sent in the header of the request. Does anyone know of a way in python to receive incoming files and retain their filenames via Bluetooth?

View 2 Replies View Related

Programming :: DataBase In Python - Compile .py Files Into A .exe File

Jun 20, 2011

i am new to python programing and i have a couple of ?'s

1- what would i do if i needed to find the closest, bigger number, from a list of numbers when the user types a number in.

2- (windows) i need a program that can compile .py files into a .exe file so that it works on a machine without python it also needs to work with python 3.2.

View 8 Replies View Related

Programming :: Python Script Integration - Monitoring File?

Apr 5, 2011

Is there any way to make program in linux machine to make report when some files have been copy to another directory or machine and knows the users who copy the files, I am planning to make this program in c, honestly first time I want to make in python when I know about pyinotify and how easy to monitoring the file in machine, but the problem is I cannot integrate that script python to know the users who do that except for the one who create the file.

View 4 Replies View Related

Programming :: Converting A HTML File To A PNG File Through Python Script?

Jan 29, 2010

I have managed to create a HTML file inside python code,convert this to a PNG file through a Python script ?

EDIT: Details added: I have a python script which generates map-legends in the form of an html file. The legend generated have to be pasted on a map which is in a png format. A png format file can be pasted on another png format file easily. But because the legends generated are in a html format I cannot paste it on the map file !!

EDIT: Details added: I did Googling first but it resulted in various soft wares for above purpose which I don't want !!

View 12 Replies View Related

Debian Programming :: Searching For A List Of Strings In File With Python

Oct 14, 2013

I'm trying to search for several strings, which I have in a .txt file line by line, on another file.

So the idea is, take input.txt and search for each line in that file in another file, let's call it rules.txt.

So far, I've been able to do this, to search for individual strings:

Code: Select allimport re

shakes = open("output.csv", "r")

for line in shakes:
    if re.match("STRING", line):
        print line,

How can I change this to input the strings to be searched from another file?

So far I haven't been able to.

View 3 Replies View Related

Programming :: Lilypond Parser For Python - Typeset The Content Of File

Nov 12, 2009

I'm woring on a personal research project and would like to know if there are lilypond parsers for python available or I'll have to create my own. Just in case you are wondering: I don't need to typeset the content of the lilypond file, just understand what's written in the file (what notes, what duration, when in time to play each one, etc). [url]

View 1 Replies View Related

Programming :: Waiting For File To Copy Before Continuing Processing (Python)

Mar 25, 2010

I have a Python script that copies a couple of DLL's and EXE to a directory before running the EXE. It can be a fresh copy or the files can already be in the target directory and are then overwritten. The script uses shutil.copy() to copy the files and that works but as the files are copying processing continues and the script tries to run the files mid copy, causing an error.

I need a way to wait for the files to finish copying before the script continues. Putting the thread to sleep isn't good enough, calling os.system("copy ...") also doesn't work, using os.path.exist() won't work because the file will exist during the copy.

View 2 Replies View Related

Programming :: Writing Files With Python Produces Blank 0KB File?

Jun 22, 2010

I am working on a little project in python. i have produced this prototype

Code:
#!/usr/bin/python
# -*- coding: iso-8859-1 -*-
#DocC documentation prototype

[Code].....

View 2 Replies View Related

Programming :: Using Python To Merge Two Text Files Line For Line

Jul 6, 2010

I'm a bit new to Python programming and hoped that someone might be able to help with a problem I'm having. What I essentially want to do is to combine two text files line for line. I know how to do this in a bash script so to give you a better idea here's the code for that:

Code:

This is basically for adding on values to the end of a CSV file that uses ';' as the delimiter. So say file1 said:

And file2 said:

Then running this command would create merged_file1_and_file2 which would be:

The code I'm using at the moment is:

Code:

As I'm sure any experienced python programmer will see, this prints out the first line of the file "csvraw" and then all of the lines of "stamps" and then the remainder of "csvraw".

What I'd like to do is something like: (pseudo code, I know it's not python ;-))

Code:

Is this possible? I've tried googling and my Python Pocket Reference hasn't been much help. I've looked at pickling but that doesn't seem appropriate.

View 1 Replies View Related

General :: Get Apt-get To Install Python Packages For A Different Version Of Python?

Oct 27, 2010

in ubuntu 10.10, I have installed python 2.7. I would like to use apt-get to install packages to this version of python but I haven't been able to figure out howThings I have tried without success:changing the symlink at /usr/bin/python to point to /usr/bin/python2.7 - even after doing this apt-get still installs stuff to python2.6.Set up python2.7 as the primary alternative using update-alternatives - doesn't work

View 3 Replies View Related

Software :: Python 3 Want Situation For Python 2 And Become Stop?

Jul 17, 2010

Python 3 want situation for python 2?Python 2 become stop?

View 1 Replies View Related

CentOS 5 :: Yum - Python-devel / Python Dependency

Jan 7, 2011

yum dependency problem please? I am running Centos 5.5. I need to install python-devel, but when I do so I get:

[Code]....

View 2 Replies View Related

Programming :: Reading Text File Into An Array

Oct 20, 2010

I know that this is a really simple thing to do but I just can't figure it out. How do I read a text file into an array in C++?

View 3 Replies View Related

Programming :: Reading A File Of Data In An Array?

Feb 10, 2011

I have two files of data with different numbers of columns and rows. I want to read this two files in two arrays and then compare for example the second column of first data file with the third column of the other text file and if the difference between of two numbers is less than a threshold then the program print the information in the rows which fulfill this condition in the third text file. I have written below program but the problem is that it does not go through all rows of second file.

declare -a a
declare -a b
r=` awk '{n++} END {print n}' second.txt `
echo $r
awk '
{

[Code]....

Actually I have two data files one of them contains 44406 and the other one has 12066 rows and I want to check whether the difference between the components of two specific columns is less than a threshod but I have simplified it here. I had written this code and then I have realized that this code just goes through the number of rows as the same as the first.txt file and ignores the rest. I could not find the problem yet.

View 2 Replies View Related

Programming :: Bash: Split A Text File Into An Array?

Sep 18, 2010

I have a file (called twitterstatus.tmp) that looks like this:

Code:

<status>
<id>24854489768</id>
<text>Are we gonna ride the sun home?</text>
<id>55266987</id>

[code].....

How could I feed this into an array, with each element containing everything between the <status> </status> tags?

View 9 Replies View Related

CentOS 5 :: Python Files Displayed As Text?

Dec 31, 2010

I have CentOS 5 32 bit and I wish to be able to use Python as it is required by a web script I am installing.The Apache however handles the test Python scripts as text. I have Apache/2.2.3 installed and I followed this tutorial: [URL]installed mod_python, edited the httpd.conf file, restarted the Apache, it restarted ok - no change at all. I tried other suggestions I googled but in vain.

View 4 Replies View Related

CentOS 5 :: Upgrade Python-2.4.3 To Python-2.5?

Mar 30, 2011

How can I upgrade python-2.4.3 to python-2.5?

View 1 Replies View Related

Software :: Use Text-voice And Vice-versa Using Python?

Jun 9, 2011

how can I use text-voice and vice-versa using python , one that looked on Python's Burrow (python.org):[URL]

View 1 Replies View Related

General :: Python Script Parse NMEA Data From GlobalSat BU-353?

Apr 7, 2010

Does anyone know where I can find a python script that will parse the lat/long data from the serial NMEA output of a BU-353.

View 1 Replies View Related

Programming :: Reading In A Outside Text File And Putting In The String On That Line Into A Char Array That Is Already Allocated?

Mar 29, 2011

Here is the issue. I am reading in a outside text file and putting in the string on that line into a char array that is already allocated.

Code:
int main(int argc, char *argv[])
{

[code]....

View 1 Replies View Related

Programming :: C++ - Store A Text File In A Data Structure?

May 25, 2009

I am writting a program that reads a text file (music.txt) & stores it in a Data Structure. I am a novice learning over the internet so I this is something I have never done. How do I do this?

Quote:

Write a program that reads the data from the music.txt file and store it in a data structure. To implement this data structure you must use an array of songs and each song must be represented by a struct with appropriate fields. So far all I can do is open to file to read it (very simple I know) but so far is it correct?

Code:

#include <iostream>
#include <fstream>
#include <strstream>

[code]....

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved