Hi,
how can I extract 2 integers from a string in python?
for example, my source string is this:
Total size: 173233 (371587)
I want to extract the integer 173233 and 371587 from that soource
string, how can I do that? 4 2886 yi*****@gmail.c om wrote: Hi,
how can I extract 2 integers from a string in python?
for example, my source string is this: Total size: 173233 (371587)
I want to extract the integer 173233 and 371587 from that soource string, how can I do that?
Use split() to split the string into four strings, using spaces as
separators, then use int() to convert the resulting strings that
interest you. a, b, c, d = 'Total size: 173233 (371857)'.split () first_int, second_int = int(c), int(d[1:-1]) first_int
173233 second_int
371857
HTH
Steve P yi*****@gmail.c om skrev: how can I extract 2 integers from a string in python?
for example, my source string is this: Total size: 173233 (371587)
I want to extract the integer 173233 and 371587 from that soource string, how can I do that?
E.g.:
#v+ import re re.findall(r'\d +', 'Total size: 173233 (371587)')
['173233', '371587']
#v-
Mvh,
--
Klaus Alexander Seistrup
Copenhagen, Denmark http://surdej.dk/
Stephen Prinster <pr******@mail. com> wrote: a, b, c, d = 'Total size: 173233 (371857)'.split () first_int, second_int = int(c), int(d[1:-1])
int(d[1:-1]) can be replaced by d.strip("()"), which may or
may not be clearer in intent.
--
\S -- si***@chiark.gr eenend.org.uk -- http://www.chaos.org.uk/~sion/
___ | "Frankly I have no feelings towards penguins one way or the other"
\X/ | -- Arthur C. Clarke
her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
In article <e6**********@m inji.szn.dk>,
Klaus Alexander Seistrup <kl***@seistrup .dk> wrote: yi*****@gmail. com skrev:
how can I extract 2 integers from a string in python?
for example, my source string is this: Total size: 173233 (371587)
I want to extract the integer 173233 and 371587 from that soource string, how can I do that?
E.g.:
#v+
import re re.findall(r'\d +', 'Total size: 173233 (371587)')['173233', '371587']
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Ren |
last post by:
Suppose I have a file containing several lines similar to this:
:10000000E7280530AC00A530AD00AD0B0528AC0BE2
The data I want to extract are 8 hexadecimal strings, the first of
which is E728, like this:
:10000000 E728 0530 AC00 A530 AD00 AD0B 0528 AC0B E2
Also, the bytes in the string are reversed. The E728 needs to be 28E7,
|
by: beliavsky |
last post by:
By mistake I coded something like
print ("1" > 1)
and got the result "True". Comparing an integer and a string seems
meaningless to me, and I would prefer to have an exception thrown. Can
someone explain why Python allows comparisons between integers and
strings, and how it handles those cases? Why is "1" > 1?
Pychecker does not warn about the line of code above -- I wish it did.
|
by: grghoward |
last post by:
I am receiving a series of Microsoft Word documents from web clients
that they upload to my server. I need to convert them to XML to pass
through to another system. I have done this through Microsoft Word
2003 with the "Save as XML" option. Now the tricky part is that a
portion of these documents contains a numbered outline. Unfortunately,
I need to remove the numbering before passing the data to the next
system. Here is an example of...
|
by: Amit Khemka |
last post by:
Hello All,
say you have some string: ", foobar "
Now i want to extract all substrings for which
"isinstance(eval(substr), list)" is "True" .
now one way is to walk through the whole sample string and check the
condition, I
was wondering if there is any smarter way of doing the same, may be
using regular-expressions.
|
by: flit |
last post by:
Hello All,
Using poplib in python I can extract only the headers using the .top,
there is a way to extract only the message text without the headers?
like remove the fields below:
"
Return-Path:
X-Original-To:
Received: from
| |
by: erikcw |
last post by:
Hi all,
I'm trying to extract zip file (containing an xml file) from an email
so I can process it. But I'm running up against some brick walls.
I've been googling and reading all afternoon, and can't seem to figure
it out.
Here is what I have so far.
p = POP3("mail.server.com")
|
by: napolpie |
last post by:
DISCUSSION IN
USER nappie writes:
Hello, I'm Peter and I'm new in python codying and I'm using parsying
to extract data from one meteo Arpege file. This file is long file and
it's composed by word and number arguments like this: GRILLE EURAT5
Coin Nord-Ouest : 46.50/ 0.50 Coin Sud-E
Hello,
I'm Peter and I'm new in python codying and I'm using parsying to
extract data from one meteo Arpege file.
|
by: Summercool |
last post by:
i think in Ruby, if you have an array (or list) of integers
foo =
you can use foo.join(",") to join them into a string "1,2,3"
in Python... is the method to use ",".join() ? but then it must take
a list of strings... not integers...
any fast method?
|
by: Edwin.Madari |
last post by:
from each line separate out url and request parts. split the request into key-value pairs, use urllib to unquote key-value pairs......as show below...
import urllib
line = "GET...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |