Hello, i am translating a program that I wrote in perl to python, i am currently stuck on this section and it does not work.
Perl: -
[while (<MAYA>)
-
{
-
-
my ($line) = $_;
-
chomp($line);
-
-
if ($line =~ /library_geometries/)
-
{
-
$start = 1;
-
}
-
-
if ($line =~ /<\/float_array>/)
-
{
-
$end = 1;
-
}
-
-
if (($start == 1) && ($end == 0))
-
{
-
if ($line !~ /</)
-
{
-
#print GRID "$line\n";
-
-
@Split = split(/ /,$line);
-
push @xCoords, $Split[0];
-
push @yCoords, $Split[1];
-
push @zCoords, $Split[2];
-
-
}
-
}
-
}]
PYTHON: WHAT I DID! -
[while Maya:
-
{
-
my (line) =
-
string.rstrip(line)
-
-
elif line in re.search("library_geometries"):
-
-
{
-
start == 1
-
}
-
-
if (line == float.array)
-
{
-
end == 1
-
}
-
-
if ((start == 1), (end == 0))
-
{
-
if (line)
-
{
-
print('Line \n')
-
-
array(Split) = split(
-
array.index(Split) = split(line)
-
push array.index(xCoords), Split(0)
-
push array.index(yCoords), Split(1)
-
push array.index(zCoords), Split(2)
-
-
-
}
-
}
-
}
-
}
-
}
-
}
-
}
-
]
3 2202 bvdet 2,851
Expert Mod 2GB
Note my comments below: - # Assume you are iterating on an open file object or list of strings?
-
for line in Maya:
-
line = line.rstrip()
-
if "library_geometries" in line:
-
start == 1
-
-
# What is float.array?
-
# float has no attribute "array"
-
elif line == float.array:
-
end == 1
-
-
# Where is end assigned to 0?
-
if start == 1 and end == 0:
-
# Is this a test for "not None"?
-
if line:
-
print('Line \n')
-
-
# Your parentheses are unbalanced
-
# I can't even guess what the following code does
-
# Python has no reserved word "push"
-
array(Split) = split(
-
array.index(Split) = split(line)
-
push array.index(xCoords), Split(0)
-
push array.index(yCoords), Split(1)
-
push array.index(zCoords), Split(2)
Float array tells the program to stop searching, if it finds library.geometries then it continues, but when it sees float.array it tells the program to stop, push is in perl, in python its list.append
Here is the one I just finished, but I can't seem to run it. - while Maya():
-
import re
-
{
-
line in []
-
-
(p) == re.compile('library_geometries')
-
(m) == p.search('library_geometries')
-
-
if m in (p)
-
start = 1
-
-
else:
-
-
p = re.compile('floar_array')
-
m = p.search('float_array')
-
-
if m:
-
end = 1
-
-
if ((start == 1), (end == 0))
-
-
else line in
-
print('Line \n'
-
Split[] = split(line)
-
list.append([xCoords], Split(0)
-
list.append([yCoords]), Split(1))
-
list.append([zCoords]), Split(2))
-
-
-
}
-
}
-
}
-
}
-
}
-
}
-
}
Go to python.org and read something about Python syntax.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Fred Ma |
last post by:
Hello,
This is not a troll posting, and I've refrained from
asking because I've seen similar threads get all
nitter-nattery. But I really want to make a decision
on how best to invest my time....
|
by: Xah Lee |
last post by:
while programing in Python, one can lookup syntax or info for keywords
or modules within Python.
In the command line, type
python
to get into the python interactive program. then type...
|
by: Xah Lee |
last post by:
# -*- coding: utf-8 -*-
# Python
# to open a file and write to file
# do
f=open('xfile.txt','w')
# this creates a file "object" and name it f.
# the second argument of open can be
|
by: Xah Lee |
last post by:
© # -*- coding: utf-8 -*-
© # Python
©
© # in Python, one can define a boxed set
© # of data and functions, which are
© # traditionally known as "class".
©
© # in the following, we define a...
|
by: Xah Lee |
last post by:
# -*- coding: utf-8 -*-
# Python
# some venture into standard modules
import os
# print all names exported by the module
print dir(os)
|
by: Xah Lee |
last post by:
suppose you want to do find & replace of string of all files in a
directory.
here's the code:
©# -*- coding: utf-8 -*-
©# Python
©
©import os,sys
©
©mydir= '/Users/t/web'
|
by: Xah Lee |
last post by:
# -*- coding: utf-8 -*-
# Python
# suppose you want to fetch a webpage.
from urllib import urlopen
print
urlopen('http://xahlee.org/Periodic_dosage_dir/_p2/russell-lecture.html').read()
#...
|
by: Xah Lee |
last post by:
here's another interesting algorithmic exercise, again from part of a
larger program in the previous series.
Here's the original Perl documentation:
=pod
merge($pairings) takes a list of...
|
by: Xah Lee |
last post by:
Sort a List
Xah Lee, 200510
In this page, we show how to sort a list in Python & Perl and also
discuss some math of sort.
To sort a list in Python, use the “sort” method. For example:
...
|
by: Xah Lee |
last post by:
Split File Fullpath Into Parts
Xah Lee, 20051016
Often, we are given a file fullpath and we need to split it into the
directory name and file name. The file name is often split into a core...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |