Sponsored Content
Full Discussion: Simple Python Code Question
Top Forums Shell Programming and Scripting Simple Python Code Question Post 303018061 by wisecracker on Monday 28th of May 2018 09:21:33 AM
Old 05-28-2018
Again I have no idea why so convoluted a method as your function:
DEMO:
Code:
#!/usr/bin/python2.7

mylist = [ "hello", "you", "are", "so", "cool" ]

STRING = ' '.join(mylist)
NEWSTRING = STRING.replace('hello', "hi")
print STRING
print NEWSTRING
print

# This function should work on ANY version of Python from at least 1.4.
def printWithoutNewlines():
    mystring = ""
    for objects in mylist:
        objects = objects.replace('hello', "hi")
        mystring = mystring + objects + " "
    return(mystring)

print printWithoutNewlines()

functionsOutput_sp = printWithoutNewlines()

print functionsOutput_sp

functionsOutput_nl = functionsOutput_sp.replace(' ', '\n')

print functionsOutput_nl ,

Results, same machine as before.
Code:
Last login: Mon May 28 14:14:06 on ttys000
AMIGA:barrywalker~> cd ~/Desktop/Code/Python
AMIGA:barrywalker~/Desktop/Code/Python> python
Python 2.7.10 (default, Oct  6 2017, 22:29:07) 
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> dir()
['__builtins__', '__doc__', '__name__', '__package__']
>>> execfile("loop.py")
hello you are so cool
hi you are so cool

hi you are so cool 
hi you are so cool 
hi
you
are
so
cool
>>> dir()
['NEWSTRING', 'STRING', '__builtins__', '__doc__', '__name__', '__package__', 'functionsOutput_nl', 'functionsOutput_sp', 'mylist', 'printWithoutNewlines']
>>> exit()
AMIGA:barrywalker~/Desktop/Code/Python> _

 

7 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Ok simple question for simple knowledge...

Ok what is BSD exactly? I know its a type of open source but what is it exactly? (1 Reply)
Discussion started by: Corrail
1 Replies

2. Red Hat

Writing simple python setup commands

Building software in most languages is a pain. Remember ant build.xml, maven2 pom files, and multi-level makefiles? Python has a simple solution for building modules, applications, and extensions called distutils. Disutils comes as part of the Python distribution so there are no other packages... (0 Replies)
Discussion started by: Linux Bot
0 Replies

3. Shell Programming and Scripting

Help with Simple Perl/Python Script

I have the following problem, which I need done in Perl/ or Python using Unix/linux filters... 1. You have a very large file, named 'ColCheckMe', tab-delmited, that you are asked to process. You are told that each line in 'ColCheckMe' has 7 columns, and that the values in the... (1 Reply)
Discussion started by: Swapnilsagarwal
1 Replies

4. Homework & Coursework Questions

Help with Simple Perl/Python Script

I have the following problem, which I need done in Perl/ or Python using Unix/linux filters... 1. You have a very large file, named 'ColCheckMe', tab-delmited, that you are asked to process. You are told that each line in 'ColCheckMe' has 7 columns, and that the values... (1 Reply)
Discussion started by: Swapnilsagarwal
1 Replies

5. Programming

Simple encryption in python

Hi, i have the below script: ###############################SimpleEncryption################################ #Simple encryption implemented in python #Author:pandeeswaran ############################################################################### def Encrypt(input): res='' ... (13 Replies)
Discussion started by: pandeesh
13 Replies

6. Red Hat

Syslog.conf: looking for a simple answer on a simple question

Cheers! In /etc/syslog.conf, if an error type is not specified, is it logged anywhere (most preferable is it logged to /var/log/messages) or not? To be more precise I am interested in error and critical level messages. At default these errors are not specified in syslog.conf, and I need to... (6 Replies)
Discussion started by: dr1zzt3r
6 Replies

7. OS X (Apple)

Python script to do simple audio capture...

This site is the first to get this snippet. It will capture an audio recording of any time length within the limits of OSX's QuickTime Player's capablility... A shell script derivative of this will be used as a further capture for CygWin's AudioScope.sh. Thoroughly read ALL the comments in... (0 Replies)
Discussion started by: wisecracker
0 Replies
DH_PYSUPPORT(1) 						  python-support						   DH_PYSUPPORT(1)

NAME
dh_pysupport - use the python-support framework to handle Python modules SYNOPSIS
dh_pysupport [debhelper options] [-V X.Y] [-X item [...]] [-n] [module dirs ...] DESCRIPTION
dh_pysupport is a debhelper program that will scan your package, detect public modules in /usr/lib/pythonX.Y/site-packages, and move them to the shared Python modules location. It will generate appropriate postinst/prerm scripts to byte-compile modules installed there for all available python versions. It will also look for private Python modules and will byte-compile them with the current Python version. You may have to list the directories containing private Python modules. If a file named debian/pyversions exists, it is used to determine the python versions with which the package can work. Appropriate dependencies on python-support, python and pythonX.Y are put in ${python:Depends}. The ${python:Versions} and ${python:Provides} optional substitution variables are made available as well. OPTIONS
module dirs If your package installs private python modules in non-standard directories, you can make dh_pysupport check those directories by passing their names on the command line. By default, it will check /usr/lib/$PACKAGE, /usr/share/$PACKAGE, /usr/lib/games/$PACKAGE and /usr/share/games/$PACKAGE -n, --noscripts Do not modify postinst/postrm scripts. -d This option is deprecated. -V X.Y Force private modules to be bytecompiled with the specific X.Y python version, regardless of the default python version on the system. -X item, --exclude=item Exclude files that contain "item" anywhere in their filename from being taken into account to generate the python dependency. It also excludes them from byte-compilation. You may use this option multiple times to build up a list of things to exclude. CONFORMS TO
Python policy as of 2006-08-10 SEE ALSO
debhelper(7) This program is a part of python-support but is made to work with debhelper. AUTHORS
Josselin Mouette <joss@debian.org>, Raphael Hertzog <hertzog@debian.org> 1.0.15 2012-06-30 DH_PYSUPPORT(1)
All times are GMT -4. The time now is 07:46 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy