Help with Python Code Whitespace


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with Python Code Whitespace
# 1  
Old 06-11-2009
Help with Python Code Whitespace

Hello All,

I have some python code that pulls together titles and displays them on web pages.

Here is the section of code I am struggling with:

#string to grab title

titlePattern =r'''\s*(\([^\)]+\))?(?P<title>.*)'''

#returns the title part of the subject line

def getTitle (self,data):

return re.search (

PartParser.titlepattern,

self.getSubject (data),

re.X

).group ("title)


This code will print out a title with whitespace in the midde od the title

ie: This is a (whitespace here, spaces or tabs) great day.

I am trying to use join and split to make the tile read

ie: This is a great day.

I believe I can remove the whitespace with

newtitlePattern = ' '.join(titlePattern(1).split())

and

PartParser.newtitlePattern

but I an not sure where to put this in the code.

Please help
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Two problems with my python code

Hello everyone , I need your help to end my python code. I've this code in python : from ipywidgets import interact, Dropdown from ipywidgets import * from ipywidgets.embed import embed_minimal_html import pandas as pd import os import sys #################### Dropdown servers... (1 Reply)
Discussion started by: Tim2424
1 Replies

2. Programming

What is wrong with below python inheritance code?

I am using python 3.4. Below is the exception I am getting- Traceback (most recent call last): File "./oop.py", line 20, in <module> y = DerivedClass("Manu") File "./oop.py", line 15, in __init__ super().__init__(self,value) TypeError: __init__() takes 2 positional arguments but... (2 Replies)
Discussion started by: Tanu
2 Replies

3. Shell Programming and Scripting

Simple Python Code Question

I have the following code: #!/usr/bin/env python mylist = def printWithoutNewlines(): for objects in mylist: #print(objects) objects = objects.replace('hello', "hi") print objects When executed, it gives the following output: ## ./loop.py hi... (3 Replies)
Discussion started by: SkySmart
3 Replies

4. Programming

Curl alternative for python code

Need to run this api command via curl, the python code works without any problems , but we want the same to be run as curl command import requests params = {'username': 'testuser'} params = 'c3NhbmthMDJjsd' params = 'test' params = 'guide' params = '192.168.0.37' params =... (2 Replies)
Discussion started by: iron_michael86
2 Replies

5. Shell Programming and Scripting

conversion of code in perl and python

How to convert below bash code in perl and python. for BLOCK in /sys/block/emcpow* do echo "100000" > "$BLOCK"/queue/nr_requests echo "noop" > "$BLOCK"/queue/scheduler done (2 Replies)
Discussion started by: learnbash
2 Replies

6. Programming

Compiling and running Python code

Hey there, First post here in the Unix forums, but I have used them a lot for research over the last year. Anyways, to why I'm here now: I'm working on a project and I'll be using the AIS Parser SDK by Brian C. Lane (can't post the link, but google that and the first 8 links will be relevant) ... (4 Replies)
Discussion started by: pmd006
4 Replies

7. Shell Programming and Scripting

How to match (whitespace digits whitespace) sequence?

Hi Following is an example line. echo "192.22.22.22 \"33dffwef\" 200 300 dsdsd" | sed "s:\(\ *\ \):\1:" I want it's output to be 200 However this is not the case. Can you tell me how to do it? I don't want to use AWK for this. Secondly, how can i fetch just 300? Should I use "\2"... (3 Replies)
Discussion started by: shahanali
3 Replies

8. Shell Programming and Scripting

Python - how to get rid of whitespace

Hello, I am trying to figure out how to get rid of whitespace that is in certain areas (Title) of HTML pages that are created be a python script. IE: This is the title. (tabs are creating these spaces) This is another title. (tabs are creating these spaces)... (5 Replies)
Discussion started by: jhampt
5 Replies

9. Shell Programming and Scripting

python code...convert to ksh or sh

Helloo... I am not much familiar with python..I found this small script in python I even do not have python on my computer...can anyone help me out to convert this into ksh or sh.. PLEASE any help I will appreciate.. here is python code.. #!/usr/bin/env python import random # Get a... (3 Replies)
Discussion started by: amon
3 Replies

10. Shell Programming and Scripting

Code conversion from JSP to PYTHON

Guys I need to convert a code from JSP (Java Tags are also there inside JSP) to PYTHON. I have OK kind of knowledge in PYTHON, but dont have a muck knowledge in JAVA/JSP. Any idea how to approach? Thanks in advance to all C Saha (1 Reply)
Discussion started by: csaha
1 Replies
Login or Register to Ask a Question
lp-shell(1)						      General Commands Manual						       lp-shell(1)

NAME
lp-shell - Open an interactive launchpadlib shell. SYNOPSIS
lp-shell [-a] [-cPROGRAM] [--python] [--ipython] [service] [LP API version] DESCRIPTION
lp-shell opens an interactive Python shell with a launchpadlib.Launchpad object "lp" which is ready for use. It authenticates against Launchpad with the consumer name "udt-lp-shell". When using lp-shell with the -a option it will use the anonymous login from launchpadlib.Launchpad. By default lp-shell connects to the "production" Launchpad service using the "1.0" LP API version. If you want to connect to another Launchpad service, call lp-shell with the service name as the second argument. lp-shell supports all ser- vices known by launchpadlib Python module. Currently known are (list can be incomplete or outdated): "production", "staging", "dogfood". A different LP API version can be selected by passing the API version to use as the third argument. Current supported are: "beta", "1.0" and "devel". OPTIONS
-a Login anonymously into Launchpad. -c PROGRAM Don't enter a shell but only run the specified Python program and exit. --ipython Use an ipython shell if available (default). --python Use a regular python shell. AUTHORS
lp-shell was written by Martin Pitt <martin.pitt@ubuntu.com>. It is released under the terms of the GNU General Public License, version 2 or (at your option) any later version. lptools 27 March 2010 lp-shell(1)