string character count
iainking at gmail.com
Wed Jul 1 11:52:24 CEST 2009
On Jun 30, 6:27 pm, noydb <jenn.du... at gmail.com> wrote:
> If I have a string for a file name such that I want to find the number
> of characters to the left of the dot, how can that be done?
> I did it this way:
> x = "text12345.txt"
> dot = x.find('.')
> print dot
> Was curious to see what method others would use - helps me learn. I
> guess I was most curious to see if it could be done in one line.
> And, how would a char count be done with no dot -- like if the string
> were "textstringwithoutdot" or "no dot in text string"?
root, ext = os.path.splitext(x)
or in one line (assuming you've imported os):
More information about the Python-list