Sponsored Content
Top Forums Shell Programming and Scripting Need python script to read a file Post 302981953 by wisecracker on Wednesday 21st of September 2016 03:32:54 PM
Old 09-21-2016
Well the reqirements here are nothing like your OP!
I noticed that you edited your post what was the edit???
Try this; it CAN be slimmed down. I will let you do that...
Code:
# python 2.7.x
f=open("/Users/barrywalker/data.txt", "r")
for line in f.readlines():
	lst=line.split(":")
	username=lst[0]
	password=lst[1]
	groups=lst[2]
	print "Username=%s" %(username)
	print "Password=%s" %(password)
	print "Groups=%s" %(groups)
f.close()

Results:-
Code:
Last login: Wed Sep 21 20:14:55 on ttys000
AMIGA:barrywalker~> cd Desktop/Code/Python
AMIGA:barrywalker~/Desktop/Code/Python> python
Python 2.7.1 (r271:86832, Jul 31 2011, 19:30:53) 
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> execfile("lst_test.py")
Username=user1
Password=psw1
Groups=Moni,Admi

Username=user2
Password=psw2
Groups=Depl,Moni,Admi

>>> exit()
AMIGA:barrywalker~/Desktop/Code/Python> _

IMPORTANT NOTE:-
you will be re-using the same variables per line loop!
You will have to intercept each loop to do something with the variables, that is up to you.

EDIT:-
Cure copy and paste in code.

Last edited by wisecracker; 09-21-2016 at 05:05 PM..
This User Gave Thanks to wisecracker For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to run a python program on multiple entries in a file

Hello I am trying to run a python program using shell script, which takes a single argument from a file. This file has one entry per line : 1aaa 2bbb 3ccc 4ddd 5eee ... ... ... My shell script runs the program, only for the last entry : #!/bin/sh IFS=$'\n' for line in $(cat... (2 Replies)
Discussion started by: ad23
2 Replies

2. Shell Programming and Scripting

Python Binary File Read and Parse

Hi to everyone :), i have a challenge right now in python that for now needs a bit of help in one part of the c0de. The task is create a new file with the name of the file defined by the ASCII content between the 3 byte and the 16 byte that is parsed from the binary file, the file is over 20 Mb i... (0 Replies)
Discussion started by: drd0spt
0 Replies

3. Shell Programming and Scripting

Plot python script output to file

Hi all, I`m trying to generate some plots using a python package named splicegrapher. I have access to a cluster which does not allow X11 forwarding and as a result I get RuntimeError: could not open display error when I use one of the plotting scripts (attached). How do I modify the script... (1 Reply)
Discussion started by: newbie83
1 Replies

4. Shell Programming and Scripting

**python** unable to read the background color in python

I am working on requirement on spreadsheet in python scripting. I have a spreadsheet containing cell values and with background color. I am able to read the value value but unable to get the background color of that particular cell. Actually my requirement is to read the cell value along... (1 Reply)
Discussion started by: giridhar276
1 Replies

5. Shell Programming and Scripting

Pass File name and Directory Path through command to python script

I'm writing python script to get the file-names in the current directory and file sizes .I'm able to get file list and their sizes but unable to pass them through command line. I want to use this script to execute on other directory and pass directory path with file name through command line. Any... (1 Reply)
Discussion started by: etldeveloper
1 Replies

6. Shell Programming and Scripting

How is html code read, compared to say python?

so, the first line of bash, perl, python, ruby, and similar languages must contain the path to the interpreter...i.e. #!/bin/perl, or #!/bin/python. so in the case of a perl script, for instance, a perl script cannot and will never run if the perl program is not installed/present on the system. ... (9 Replies)
Discussion started by: SkySmart
9 Replies

7. Shell Programming and Scripting

Python Script to take file count and insert into DB2 table

Team I have files in different directories . How can i take the count of latest file and insert into Db2 table . I am using awk 'END{print NR+1-ARGC}' (File name) to get the counts. How can i take 1.The count of latest file 2.Insert into Db2 table( File Name and Counts) . cd... (4 Replies)
Discussion started by: Perlbaby
4 Replies

8. Windows & DOS: Issues & Discussions

How to execute python script on remote with python way..?

Hi all, I am trying to run below python code for connecting remote windows machine from unix to run an python file exist on that remote windows machine.. Below is the code I am trying: #!/usr/bin/env python import wmi c = wmi.WMI("xxxxx", user="xxxx", password="xxxxxxx")... (1 Reply)
Discussion started by: onenessboy
1 Replies

9. Shell Programming and Scripting

Feed python with read line in shell

Hello, I am running under ubuntu 14.04. I have a python file bringing requested data. When I run, it asks me to enter query info. After that, it gives the data if anything matched can be found. What I need to accomplish is, instead of entering the requested data from keyboard, to put all... (11 Replies)
Discussion started by: baris35
11 Replies

10. Programming

Python script to grep fields and use values from file 1 as argument for another command

Hi Experts, I am working one one python script in version 3.x and 2.6. Need your support to complete it Basically for both commands i have telnet to device and run command and then receiving input File 1 and File 2 I have two commands, need to grep data and output in csv file. Next script/code... (0 Replies)
Discussion started by: as7951
0 Replies
renpy(6)							       Games								  renpy(6)

NAME
renpy - engine for creating visual novels SYNOPSIS
renpy [path to the script directory] DESCRIPTION
Ren'Py is a programming language and runtime, intended to ease the creation of visual-novel type games. It contains features that make it easy to display thoughts, dialogue, and menus; to display images to the user; to write game logic; and to support the saving and loading of games. Ren'Py tries to be like an executable script, allowing you to get a working game without much more effort than is required to type the game script into the computer. Ren'Py is implemented on top of python, and that python heritage shows through in many places. Many Ren'Py statements allow python expres- sions to be used, and there are also Ren'Py statements that allow for the execution of arbitrary python code. Many of the less-used fea- tures of Ren'Py are exposed to the user by way of python. By only requiring use of the simplest features of python, it's hoped that Ren'Py will be usable by all game authors. USAGE
If you run the program without any arguments, zou will get an interactive launcher from where you can select, run and work different projects. For running a script, you need to give the full path to the directory that contains the game you want to play. For example: renpy /usr/share/games/renpy/demo/ To learn how to use the game interface, you should install and play renpy-demo. FILES
The game data for each user is stored at ~/.renpy/ directory. The scripts can be installed in the system bz placing them under /usr/share/games/renpy/ , but you can run any script in an arbitrarz directory just by telling the path as the parameter to the game. SEE ALSO
You can find more information at http://www.renpy.org/ May 2007 renpy(6)
All times are GMT -4. The time now is 11:25 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy