I'm doing some data normalisation, which involves data from a Web site
being extracted with BeautifulSoup, cleaned up with a regex, then
having the current year as returned by time()'s tm_year attribute
inserted, before the data is concatenated with string.join() and fed
to time.strptime().
Here's some code:
timeinput = re.split('[\s:-]', rawtime)
print timeinput #trace statement
print year #trace statement
t = timeinput.insert(2, year)
print t #trace statement
t1 = string.join(t, '')
timeobject = time.strptime(t1, "%d %b %Y %H %M")
year is a Unicode string; so is the data in rawtime (BeautifulSoup
gives you Unicode, dammit). And here's the output:
[u'29', u'May', u'01', u'00'] (OK, so the regex is working)
2008 (OK, so the year is a year)
None (...but what's this?)
Traceback (most recent call last):
File "bothv2.py", line 71, in <module>
t1 = string.join(t, '')
File "/usr/lib/python2.5/string.py", line 316, in join
return sep.join(words)
TypeError 4 1010
TYR wrote:
I'm doing some data normalisation, which involves data from a Web site
being extracted with BeautifulSoup, cleaned up with a regex, then
having the current year as returned by time()'s tm_year attribute
inserted, before the data is concatenated with string.join() and fed
to time.strptime().
Here's some code:
timeinput = re.split('[\s:-]', rawtime)
print timeinput #trace statement
print year #trace statement
t = timeinput.insert(2, year)
print t #trace statement
t1 = string.join(t, '')
timeobject = time.strptime(t1, "%d %b %Y %H %M")
year is a Unicode string; so is the data in rawtime (BeautifulSoup
gives you Unicode, dammit). And here's the output:
[u'29', u'May', u'01', u'00'] (OK, so the regex is working)
2008 (OK, so the year is a year)
None (...but what's this?)
Traceback (most recent call last):
File "bothv2.py", line 71, in <module>
t1 = string.join(t, '')
File "/usr/lib/python2.5/string.py", line 316, in join
return sep.join(words)
TypeError
First - don't use module string anymore. Use e.g.
''.join(t)
Second, you can only join strings. but year is an integer. So convert it to
a string first:
t = timeinput.insert(2, str(year))
Diez
On May 29, 11:09 pm, TYR <a.harrow...@gmail.comwrote:
I'm doing some data normalisation, which involves data from a Web site
being extracted with BeautifulSoup, cleaned up with a regex, then
having the current year as returned by time()'s tm_year attribute
inserted, before the data is concatenated with string.join() and fed
to time.strptime().
Here's some code:
timeinput = re.split('[\s:-]', rawtime)
print timeinput #trace statement
print year #trace statement
t = timeinput.insert(2, year)
print t #trace statement
t1 = string.join(t, '')
timeobject = time.strptime(t1, "%d %b %Y %H %M")
year is a Unicode string; so is the data in rawtime (BeautifulSoup
gives you Unicode, dammit). And here's the output:
[u'29', u'May', u'01', u'00'] (OK, so the regex is working)
2008 (OK, so the year is a year)
None (...but what's this?)
Traceback (most recent call last):
File "bothv2.py", line 71, in <module>
t1 = string.join(t, '')
File "/usr/lib/python2.5/string.py", line 316, in join
return sep.join(words)
TypeError
list.insert modifies the list in-place:
>>l = [1,2,3] l.insert(2,4) l
[1, 2, 4, 3]
It also returns None, which is what you're assigning to 't' and then
trying to join.
Replace your usage of 't' with 'timeinput' and it should work.
On May 29, 2:23 pm, "Diez B. Roggisch" <de...@nospam.web.dewrote:
TYR wrote:
I'm doing some data normalisation, which involves data from a Web site
being extracted with BeautifulSoup, cleaned up with a regex, then
having the current year as returned by time()'s tm_year attribute
inserted, before the data is concatenated with string.join() and fed
to time.strptime().
Here's some code:
timeinput = re.split('[\s:-]', rawtime)
print timeinput #trace statement
print year #trace statement
t = timeinput.insert(2, year)
print t #trace statement
t1 = string.join(t, '')
timeobject = time.strptime(t1, "%d %b %Y %H %M")
year is a Unicode string; so is the data in rawtime (BeautifulSoup
gives you Unicode, dammit). And here's the output:
[u'29', u'May', u'01', u'00'] (OK, so the regex is working)
2008 (OK, so the year is a year)
None (...but what's this?)
Traceback (most recent call last):
File "bothv2.py", line 71, in <module>
t1 = string.join(t, '')
File "/usr/lib/python2.5/string.py", line 316, in join
return sep.join(words)
TypeError
First - don't use module string anymore. Use e.g.
''.join(t)
Second, you can only join strings. but year is an integer. So convert it to
a string first:
t = timeinput.insert(2, str(year))
Diez
Yes, tm_year is converted to a unicode string elsewhere in the program.
On May 29, 2:24 pm, alex23 <wuwe...@gmail.comwrote:
On May 29, 11:09 pm, TYR <a.harrow...@gmail.comwrote:
I'm doing some data normalisation, which involves data from a Web site
being extracted with BeautifulSoup, cleaned up with a regex, then
having the current year as returned by time()'s tm_year attribute
inserted, before the data is concatenated with string.join() and fed
to time.strptime().
Here's some code:
timeinput = re.split('[\s:-]', rawtime)
print timeinput #trace statement
print year #trace statement
t = timeinput.insert(2, year)
print t #trace statement
t1 = string.join(t, '')
timeobject = time.strptime(t1, "%d %b %Y %H %M")
year is a Unicode string; so is the data in rawtime (BeautifulSoup
gives you Unicode, dammit). And here's the output:
[u'29', u'May', u'01', u'00'] (OK, so the regex is working)
2008 (OK, so the year is a year)
None (...but what's this?)
Traceback (most recent call last):
File "bothv2.py", line 71, in <module>
t1 = string.join(t, '')
File "/usr/lib/python2.5/string.py", line 316, in join
return sep.join(words)
TypeError
list.insert modifies the list in-place:
>l = [1,2,3] l.insert(2,4) l
[1, 2, 4, 3]
It also returns None, which is what you're assigning to 't' and then
trying to join.
Replace your usage of 't' with 'timeinput' and it should work.
Thank you. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Bruno van Dooren |
last post by:
Hi All,
i have some (3) different weird pointer problems that have me stumped. i
suspect that the compiler behavior is correct because gcc shows the same
results.
...
|
by: Piotr Kurpiel |
last post by:
Hello,
I am using MS Access 2003 with VBScript. I have quite strange column names
which are: 1,2,3,4,etc... Data Types of the columns are Yes/No and formats
True/False. The first thing I want to...
|
by: Marlene Stebbins |
last post by:
Something very strange is going on here. I don't know if it's a C
problem or an implementation problem. The program reads data from
a file and loads it into two arrays. When xy, x, y, *xlist and...
|
by: Harlan Messinger |
last post by:
Since operator overloads into static functions in C#, there really doesn't
need to be a connection between the types to which the operator is being
applied and the type in which the overload is...
|
by: Amit |
last post by:
Hi
I have occured a very strange situation.
The scenario is as follows. I have two buttons in the form. First
button is Load button and the second one is Delete button. As the name
suggests...
| |
by: WhiteWizard |
last post by:
Have we got a STRANGE one going here.
We converted from 1.1 to 2.0 about 2 weeks ago and this has been a problem
since then...but only on SOME machines in our development group. The
application...
|
by: Rico |
last post by:
Hi Folks!
I have a strange thing happening; I have a field that Counts the number of
records and another field that shows the number of clients
(Count(RecordID)=3 and NoOfClients=2) When I do a...
|
by: kyagrd |
last post by:
<code>
#include <iostream>
int main(void)
{
using namespace std;
int p;
int* p1 = p;
int* p11 = p + 2;
|
by: TheSteph |
last post by:
Hi,
I have a small serializable struct :
public struct TestStruct
{
public string Title;
public int Age;
public string Name;
|
by: jbitz |
last post by:
Hi,
This has got me really baffled.
This has got me really baffled. When I run Dim url As String = HttpContext.Current.Request.Url.AbsolutePath.ToLower from Application_beginRequest in...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |