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
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
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
2. Shell Programming and Scripting
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
3. Shell Programming and Scripting
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
4. Shell Programming and Scripting
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
5. Programming
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
6. Shell Programming and Scripting
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
7. Programming
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
8. Shell Programming and Scripting
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
9. Programming
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
10. Programming
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
LEARN ABOUT DEBIAN
sgmls::refs
Refs(3pm) User Contributed Perl Documentation Refs(3pm)
NAME
SGMLS::Refs - Forward reference handling
SYNOPSIS
use SGMLS::Refs;
To create a new reference-manager object using the file "foo.refs":
my $refs = new SGMLS::Refs("foo.refs");
To create a new reference-manager object using the file "foo.refs" and logging changes to the file "foo.log":
my $refs = new SGMLS::Refs("foo.refs","foo.log");
To record a reference:
$refs->put("document title",$title);
To retrieve a reference:
$title = $refs->get("document title");
To return the number of references changed since the last run:
$num = $refs->changed;
To print a LaTeX-like warning if any references have changed:
$refs->warn;
DESCRIPTION
This library can be used together with the SGMLS package to keep track of forward references from one run to another, like the LaTeX ".aux"
files. Each reference manager is an object which reads and then rewrites a file of perl source, with the file name provided by the caller.
Example:
# Start up the reference manager before the parse.
sgml('start', sub { $refs = new SGMLS::Refs("foo.refs"); });
# Warn about any changed references at the end.
sgml('end', sub { $refs->warn; });
# Look up the title from the last parse, if available.
sgml('<div>', sub {
my $element = shift;
my $id = $element->attribute(ID)->value;
my $title = $refs->get("title:$id") || "[no title available]";
$current_div_id = $id;
output "\section{$title}
";
});
# Save the title for the next parse.
sgml('<head>', sub { push_output('string'); });
sgml('</head>', sub {
my $title = pop_output();
my $id = $current_div_id;
$refs->put("title:$id",$title);
});
AUTHOR AND COPYRIGHT
Copyright 1994 and 1995 by David Megginson, "dmeggins@aix1.uottawa.ca". Distributed under the terms of the Gnu General Public License
(version 2, 1991) -- see the file "COPYING" which is included in the SGMLS.pm distribution.
SEE ALSO
:
SGMLS, SGMLS::Output.
perl v5.8.8 2004-02-22 Refs(3pm)