LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Looking for any good idea to read python script. (https://www.linuxquestions.org/questions/linux-software-2/looking-for-any-good-idea-to-read-python-script-4175677137/)

kaz2100 06-16-2020 01:11 AM

Looking for any good idea to read python script.
 
Hya,

I have a question for python experts.

How do experts read python script, written by somebody else?

I have some sort of trouble how variables are defined, variable/module confusion...

I do not have much, but some experience with basic, Fortran, Pascal and C. Thanks to definition (header in C), it is easy to decipher Pascal and C, whereas it is easy to be entangled in spaghetti in basic. Fortran can be easy and hard.

As somebody else asked similar question, I am sure that I am NOT the only one to have similar question.

With pycharm, too many variables show up... (I guess there are dir(), vars() and some other potentially useful weapons.)

Any comments will be appreciated.

cheers

pan64 06-16-2020 01:20 AM

There are two different kind of codes available around here: well written (documented), readable good code and the others.
So it depends on the code quality, not on the language.
And obviously we need some practice and knowledge too.

dugan 06-17-2020 11:29 AM

I'm honestly not sure what answer you're expecting.

First, I know Python well. I have that foundation.

Second, I look at what external libraries the Python script uses. That can be seen in its import statements and its requirements.txt file (if it has one). I go skim their documentation.

Then, I read the Python script.

If you want tooling: a good REPL like PtPython, bpython or iPython sometimes helps, as can knowing how to use PDB. There's a PDB tutorial here:

https://github.com/spiside/pdb-tutorial

teckk 06-17-2020 12:55 PM

Quote:

How do experts read python script, written by somebody else?
You'll have to become familiar with python, and it's modules that the script uses.
https://docs.python.org/3/
https://docs.python.org/3/library/tkinter.html
https://docs.python.org/3/library/urllib.html
https://www.riverbankcomputing.com/static/Docs/PyQt5/

Also:
Code:

>>> import urllib
>>> help(urllib)

Help on package urllib:

NAME
    urllib

MODULE REFERENCE
    https://docs.python.org/3.8/library/urllib
...


kaz2100 06-17-2020 08:25 PM

Experts

Thanks for your replies.
It's true, that I do not know what I need to know.
The program uses wx, dom, urllib... Documentation of wxpython is good, wxwidgets looks good, but overwhelming... The program itself does not have doc files.
I will check one by one.

cheers

JJJCR 06-18-2020 03:32 AM

I know it's not easy to read someone's code, it's like reading someone else's mind but with some readable hints.

First: Program does what?
Second: Just try to view the whole picture, if you are the one to do it. How will you do it?
Third: What will you need? (Like libraries, etc.)
Fourth: The hardest part, understand the code. I think do it like block by block so it won't be overwhelming.

Or clone the source code, put it on a virtual environment run it and check if working perfectly.
Then, start deleting some lines on the code and run the program.
If an error occurs, then at least you will be able to get some idea and the importance of the line that was deleted.

Summary: It's not easy, it's a nightmare. Of course, depends on your level of expertise.

Lastly, once you get a hang of it. Give yourself a favor and be a nice fellow, make some documentation. :)

Good luck!!!

kaz2100 06-22-2020 08:32 PM

Experts.

Thanks for suggestions.

I am learning how to navigate with help, still not quite (difference between help(###) and help('###')).

My goal is major tune up of bibus and if possible, upgrade it to python3.

So far, I took care of
1, file() -> open()
2, gettext.install -> t = gettext.translation(...) (\n) _ = gettext (python 3.8.3 doc, under gettext.install and install())
without confidence.

Next one does not look hard, but not solved yet. I assume notation of hex numbers need modification.
Code:

BIB.ARROWS = wx.ImageList(16, 16)
BIB.ARROW_UP = BIB.ARROWS.Add(images.getSmallUpArrowBitmap())

images.py looks like
Code:

def getSmallUpArrowData():
    return \
'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x10\x08\x06\
\x00\x00\x00\x1f\xf3\xffa\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\
\x00\x00<IDAT8\x8dcddbf\xa0\x040Q\xa4{h\x18\xf0\xff\xdf\xdf\xffd\x1b\x00\xd3\
\x8c\xcf\x10\x9c\x06\xa0k\xc2e\x08m\xc2\x00\x97m\xd8\xc41\x0c \x14h\xe8\xf2\
\x8c\xa3)q\x10\x18\x00\x00R\xd8#\xec\xb2\xcd\xc1Y\x00\x00\x00\x00IEND\xaeB`\
\x82'

def getSmallUpArrowBitmap():
    return BitmapFromImage(getSmallUpArrowImage())  <*>

def getSmallUpArrowImage():
    stream = io.StringIO(getSmallUpArrowData())
    return ImageFromStream(stream)

and python3 chokes at <*>.

Another point I do not understand is (not my project related) that when initialize wx application, several scripts use a = wx.App(), while wxpython document reads wx.App(PyApp). What is PyApp? What is it for?

I will update.

cheers

pan64 06-23-2020 01:00 AM

About wx.App(PyApp): This is an initialization of an object wx.App and actually it is inherited from PyApp. PyApp is another object, see https://pypi.org/project/pyApp/.
I'm afraid you need to learn about OOP (Objectum Oritented Programming) and especially how does it work in python3.

ondoho 06-23-2020 01:44 AM

Quote:

Originally Posted by kaz2100 (Post 6137103)
My goal is major tune up of bibus and if possible, upgrade it to python3.

That looks empty.
Do you mean this https://sourceforge.net/projects/bibus-biblio/ ???

kaz2100 06-28-2020 06:29 PM

Experts

Thank you for replies.

Yes, I do need to learn OOP using wx (or whatever). I once used OOP quite a while ago, Macintosh (pre i-Mac age), following Inside Macintosh. Definition of this kind of parameters was easily found. Here, I have some trouble of finding this kind of information, --header file, Inside Macintosh or equivalent.

Another point I need to know is: how python behave when some (probably important) parameter is omitted, "a = wx.App()"?

Yes, another apology. My link was empty. https://sourceforge.net/projects/bibus-biblio/ is correct.

cheers

kaz2100 07-07-2020 02:24 AM

Hya

My problem at #7, 'b' prefix was missing.
Code:

def getSmallUpArrowData():
    return \
b'\x89PNG\r\n\x1a\n\x00\x0...


This site
says
Code:

For example, in Python 3, the type Literal["foo"] is equivalent to Literal[u"foo"], since "foo" is equivalent to u"foo" in Python 3.

Similarly, in Python 2, the type Literal["foo"] is equivalent to Literal[b"foo"] -- unless the file includes a from __future__

I still have not found if there are more prefixes.

Several other problems have taken care of, and now I need to figure out how to do with
Code:

class TitledPage(wx.wizard.WizardPageSimple):
So far, replacing the line with
Code:

TitledPage(wx.adv.WizardPageSimple):
does not work. I guess this has to do with wxpython (or wxwidgets), not python.

cheers

pan64 07-07-2020 03:34 AM

there is a tool: https://docs.python.org/3/library/2to3.html to convert python2 code to python3. It will perfectly handle all the general issues, but there can be special cases when it fails.

would be nice to post your problem exactly, like: what did you try, what did you expect, what's happened ....

kaz2100 12-01-2020 01:46 AM

Hya,

Apology for long silence. My life was not straightforward...
I have learned a little bit.

Currently, I am having trouble with dom library to parse xml file. Two problems:
1. when text contains <i>...</i>, the program chokes with exception (probably). I need to figure out where.
2. python3 dom behaves differently from python2 counterpart. An exception where python2 is happy.

With PyCharm, I have not been able to point where problematic code is.

cheers

pan64 12-01-2020 02:03 AM

Quote:

Originally Posted by kaz2100 (Post 6190511)
1. when text contains <i>...</i>, the program chokes with exception (probably). I need to figure out where.

Which text is it (looks like some kind of html).
which python script is it.
what is the error message (what's happening)

How can we help you without details?

kaz2100 12-01-2020 11:31 PM

Hya,

Thank you for your reply.

Detail of problem 1 at #13 follows.

Text (xml) can be downloaded with
Code:

wget https://www.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi\?db=PubMed\&id=31819487\&rettype=null\&retmode=xml
The script which chokes (I guess, reason: pyCharm stops with exception) is
Code:

Title = record.getElementsByTagName("ArticleTitle")[0].firstChild.data
There is no error messages.
Entire xml file is processed like
Code:

a1 = parse("ngFile.xml")
record = a1.getElementsByTagName("PubmedArticle")

I am trying to pinpoint where thing goes wrong using interactive mode, but no success yet. Script chokes, while 'step by step manually' does not.

cheers

kaz2100 12-01-2020 11:48 PM

Hya,

Thanks for your reply.

Detail of problem 2 at #13 follows.
Code:

try:
  BIB.DB_MODULE = __import__(u'dbBibSQLite')
  getattr(BIB.DB_MODULE,'dbBib')    # if the module was loaded before, re-importing won't raise ImportError. We must check directly if it works
except (ImportError,AttributeError):
  BIB.DB_MODULE = None
  wx.LogError(_("""Sorry, but I was not able to find the python module for the %s database.\nPlease check your installation""")%BIB.DB_TYPE)

python3 goes to exception, while python2 does not. (dbBibSQLite.py exists.) I am currently suspecting code (ascii utf-8) or something.

cheers

pan64 12-02-2020 01:40 AM

but why don't you show us that exception?

kaz2100 12-02-2020 08:03 PM

Hya

Thank you for your reply.

I wish I could.

When I followed execution flow (using pycharm), it goes silently into except clause.
try clause looks like
Code:

try:
  BIB.DB_MODULE = __import__(u'dbBibSQLite')
  getattr(BIB.DB_MODULE,'dbBib')
except (ImportError,AttributeError):

Neither of Debugger nor python console shows any message either. I have not found clues yet (which exception where...) I can only assume it is ImportError at __import__.

best

pan64 12-03-2020 12:59 AM

since there is an import and a getattr call too, you cannot assume it is an import error. I would try to print the full exception (just to understand what's going on).
Probably you can insert a line or two just for a test.

kaz2100 12-03-2020 02:52 AM

Hya,

Thank you for your reply.

My assumption was off target.

I tried to this __import__ clause in interactive mode, where error messages showed up. If I am on the right track, error is
Code:

..........line 36, in <module>
    %(_("Acrobat file"),\
NameError: name '_' is not defined

This is within definition of pull-down menu (wx-windows) options.
Code:

WILDCARD = "%s (*.pdf)|*.pdf|%s (*.odt)|*.odt|%s (*.doc)|*.doc|%s (*.*)|*.*"\
  %(_("Acrobat file"),\
  _("OpenOffice.org Text Document"),\
  _("Microsoft Word Document"),\
  _("All files"))

I am not sure if this is another wrong assumption. I will follow your advice.

cheers

kaz2100 12-03-2020 08:38 PM

Hya

Another incorrect assumption of mine.
Code:

except (ImportError,AttributeError) as ert:
catches AttributeError module 'wx' has no attribute 'adv'

Also, this clause cannot trap NameError, I guess.

I hope I am on the right track.

cheers

pan64 12-04-2020 02:25 AM

https://stackoverflow.com/questions/...espite-phoenix

teckk 12-04-2020 08:13 AM

If I understand you from post #15

You want to parse this xml file
Code:

url="https://www.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi\?db=PubMed\&id=31819487\&rettype=null\&retmode=xml"
And that link gives me an
Code:

<ERROR>Database: pubmed\ - is not supported</ERROR>
Code:

agent="Mozilla/5.0 (Windows NT 10.1; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0"

curl -A "$agent" "$url" -o test.xml

cat test.xml
...
invalid api-key error.

Your link is no good, needs a login or something. Can't go any farther with it until I get some valid data. Post a valid link or login if you want help parsing an xml page.

kaz2100 12-06-2020 03:33 AM

Hi, teckk

Thank you for your reply and time.

That link works for me at Sun 6 Dec 09:32:00 UTC 2020, but entire xml will be posted #25.

cheers

kaz2100 12-06-2020 03:33 AM

<?xml version="1.0" ?>
<!DOCTYPE PubmedArticleSet PUBLIC "-//NLM//DTD PubMedArticle, 1st January 2019//EN" "https://dtd.nlm.nih.gov/ncbi/pubmed/out/pubmed_190101.dtd">
<PubmedArticleSet>
<PubmedArticle>
<MedlineCitation Status="PubMed-not-MEDLINE" Owner="NLM">
<PMID Version="1">31819487</PMID>
<DateRevised>
<Year>2020</Year>
<Month>09</Month>
<Day>29</Day>
</DateRevised>
<Article PubModel="Electronic-eCollection">
<Journal>
<ISSN IssnType="Print">1178-6930</ISSN>
<JournalIssue CitedMedium="Print">
<Volume>12</Volume>
<PubDate>
<Year>2019</Year>
</PubDate>
</JournalIssue>
<Title>OncoTargets and therapy</Title>
<ISOAbbreviation>Onco Targets Ther</ISOAbbreviation>
</Journal>
<ArticleTitle><i>PDHA1</i> Gene Knockout In Human Esophageal Squamous Cancer Cells Resulted In Greater Warburg Effect And Aggressive Features In Vitro And In Vivo.</ArticleTitle>
<Pagination>
<MedlinePgn>9899-9913</MedlinePgn>
</Pagination>
<ELocationID EIdType="doi" ValidYN="Y">10.2147/OTT.S226851</ELocationID>
<Abstract>
<AbstractText Label="Background" NlmCategory="UNASSIGNED">One of the remarkable metabolic characteristics of cancer cells is that they prefer glycolysis rather than oxidative phosphorylation (OXPHOS). Pyruvate dehydrogenase E1 alpha subunit (PDHA1) is an important prerequisite for OXPHOS. Our previous studies have shown that low level of PDHA1 protein expression in esophageal squamous cell cancer (ESCC) was correlated with poor prognosis. However, the effect of PDHA1 inhibition on metabolism and biological behavior of esophageal cancer cells remains unclear.</AbstractText>
<AbstractText Label="Methods And Results" NlmCategory="UNASSIGNED">In this study, a KYSE450 PDHA1 knockout (KO) cell line of esophageal cancer was established by CRISPR/Cas9 technology. Then, the glycose metabolism, cell proliferation and migration abilities, chemotherapeutic tolerance and angiogenesis of the PDHA1 KO cells were investigated in vitro and in vivo. In the PDHA1 KO cells, the glycolysis and the consumption of glucose and glutamine were significantly enhanced, while the OXPHOS was significantly suppressed, implying Warburg effect in the PDHA1 KO cells. Furthermore, it was also proved in vitro experiments that the PDHA1 KO cell obtained proliferation advantage, as well as significantly greater chemotherapy tolerance and migration ability. Xenograft experiments discovered not only larger tumors but also increased angiogenesis in the PDHA1 KO cell group.</AbstractText>
<AbstractText Label="Conclusion" NlmCategory="UNASSIGNED">Inhibition of <i>PDHA1</i> gene expression in human ESCC leads to metabolic reprogramming of Warburg effect and increased malignancies. Targeting ESCC metabolic reprogramming may become a potential therapeutic target.</AbstractText>
<CopyrightInformation>© 2019 Liu et al.</CopyrightInformation>
</Abstract>
<AuthorList CompleteYN="Y">
<Author ValidYN="Y">
<LastName>Liu</LastName>
<ForeName>Lan</ForeName>
<Initials>L</Initials>
<Identifier Source="ORCID">0000-0002-0904-7417</Identifier>
<AffiliationInfo>
<Affiliation>Department of Pathology, School of Basic Medical Sciences, Zhengzhou University, Zhengzhou, Henan Province, People's Republic of China.</Affiliation>
</AffiliationInfo>
<AffiliationInfo>
<Affiliation>Academy of Medical Science, Zhengzhou University, Zhengzhou, Henan Province, People's Republic of China.</Affiliation>
</AffiliationInfo>
<AffiliationInfo>
<Affiliation>Department of Pathology, The Norwegian Radium Hospital, Oslo University Hospital, Institute of Clinical Medicine, University of Oslo, Montebello, Oslo, Norway.</Affiliation>
</AffiliationInfo>
</Author>
<Author ValidYN="Y">
<LastName>Cao</LastName>
<ForeName>Jing</ForeName>
<Initials>J</Initials>
<AffiliationInfo>
<Affiliation>Department of Pathology, The Third Affiliated Hospital of Zhengzhou University, Zhengzhou, Henan Province, People's Republic of China.</Affiliation>
</AffiliationInfo>
</Author>
<Author ValidYN="Y">
<LastName>Zhao</LastName>
<ForeName>Jing</ForeName>
<Initials>J</Initials>
<AffiliationInfo>
<Affiliation>Department of Oncology, The First Affiliated Hospital of Zhengzhou University, Zhengzhou, Henan Province, People's Republic of China.</Affiliation>
</AffiliationInfo>
</Author>
<Author ValidYN="Y">
<LastName>Li</LastName>
<ForeName>Xiangyu</ForeName>
<Initials>X</Initials>
<AffiliationInfo>
<Affiliation>Department of Oncology, The First Affiliated Hospital of Zhengzhou University, Zhengzhou, Henan Province, People's Republic of China.</Affiliation>
</AffiliationInfo>
</Author>
<Author ValidYN="Y">
<LastName>Suo</LastName>
<ForeName>Zhenhe</ForeName>
<Initials>Z</Initials>
<AffiliationInfo>
<Affiliation>Department of Pathology, The Norwegian Radium Hospital, Oslo University Hospital, Institute of Clinical Medicine, University of Oslo, Montebello, Oslo, Norway.</Affiliation>
</AffiliationInfo>
</Author>
<Author ValidYN="Y">
<LastName>Li</LastName>
<ForeName>Huixiang</ForeName>
<Initials>H</Initials>
<AffiliationInfo>
<Affiliation>Department of Pathology, School of Basic Medical Sciences, Zhengzhou University, Zhengzhou, Henan Province, People's Republic of China.</Affiliation>
</AffiliationInfo>
<AffiliationInfo>
<Affiliation>Department of Pathology, The First Affiliated Hospital of Zhengzhou University, Zhengzhou, Henan Province, People's Republic of China.</Affiliation>
</AffiliationInfo>
</Author>
</AuthorList>
<Language>eng</Language>
<PublicationTypeList>
<PublicationType UI="D016428">Journal Article</PublicationType>
</PublicationTypeList>
<ArticleDate DateType="Electronic">
<Year>2019</Year>
<Month>11</Month>
<Day>18</Day>
</ArticleDate>
</Article>
<MedlineJournalInfo>
<Country>New Zealand</Country>
<MedlineTA>Onco Targets Ther</MedlineTA>
<NlmUniqueID>101514322</NlmUniqueID>
<ISSNLinking>1178-6930</ISSNLinking>
</MedlineJournalInfo>
<KeywordList Owner="NOTNLM">
<Keyword MajorTopicYN="N">CRISPR/Cas9</Keyword>
<Keyword MajorTopicYN="N">ESCC</Keyword>
<Keyword MajorTopicYN="N">KYSE450</Keyword>
<Keyword MajorTopicYN="N">PDHA1</Keyword>
<Keyword MajorTopicYN="N">Warburg effect</Keyword>
<Keyword MajorTopicYN="N">xenotransplantation</Keyword>
</KeywordList>
<CoiStatement>The authors report no conflicts of interest in this work.</CoiStatement>
</MedlineCitation>
<PubmedData>
<History>
<PubMedPubDate PubStatus="received">
<Year>2019</Year>
<Month>08</Month>
<Day>12</Day>
</PubMedPubDate>
<PubMedPubDate PubStatus="accepted">
<Year>2019</Year>
<Month>10</Month>
<Day>31</Day>
</PubMedPubDate>
<PubMedPubDate PubStatus="entrez">
<Year>2019</Year>
<Month>12</Month>
<Day>11</Day>
<Hour>6</Hour>
<Minute>0</Minute>
</PubMedPubDate>
<PubMedPubDate PubStatus="pubmed">
<Year>2019</Year>
<Month>12</Month>
<Day>11</Day>
<Hour>6</Hour>
<Minute>0</Minute>
</PubMedPubDate>
<PubMedPubDate PubStatus="medline">
<Year>2019</Year>
<Month>12</Month>
<Day>11</Day>
<Hour>6</Hour>
<Minute>1</Minute>
</PubMedPubDate>
</History>
<PublicationStatus>epublish</PublicationStatus>
<ArticleIdList>
<ArticleId IdType="pubmed">31819487</ArticleId>
<ArticleId IdType="doi">10.2147/OTT.S226851</ArticleId>
<ArticleId IdType="pii">226851</ArticleId>
<ArticleId IdType="pmc">PMC6874154</ArticleId>
</ArticleIdList>
<ReferenceList>
<Reference>
<Citation>Proc Natl Acad Sci U S A. 2002 Aug 20;99(17):11205-10</Citation>
<ArticleIdList>
<ArticleId IdType="pubmed">12163646</ArticleId>
</ArticleIdList>
</Reference>
<Reference>
<Citation>J Cardiovasc Transl Res. 2013 Feb;6(1):10-21</Citation>
<ArticleIdList>
<ArticleId IdType="pubmed">23247633</ArticleId>
</ArticleIdList>
</Reference>
<Reference>
<Citation>Anticancer Res. 2015 Oct;35(10):5533-8</Citation>
<ArticleIdList>
<ArticleId IdType="pubmed">26408721</ArticleId>
</ArticleIdList>
</Reference>
<Reference>
<Citation>PLoS Biol. 2018 Jul 27;16(7):e2005869</Citation>
<ArticleIdList>
<ArticleId IdType="pubmed">30052635</ArticleId>
</ArticleIdList>
</Reference>
<Reference>
<Citation>Cell Metab. 2016 Jan 12;23(1):27-47</Citation>
<ArticleIdList>
<ArticleId IdType="pubmed">26771115</ArticleId>
</ArticleIdList>
</Reference>
<Reference>
<Citation>Hepatology. 2015 Oct;62(4):1145-59</Citation>
<ArticleIdList>
<ArticleId IdType="pubmed">26082033</ArticleId>
</ArticleIdList>
</Reference>
<Reference>
<Citation>Cell. 1997 Feb 7;88(3):323-31</Citation>
<ArticleIdList>
<ArticleId IdType="pubmed">9039259</ArticleId>
</ArticleIdList>
</Reference>
<Reference>
<Citation>Int J Biochem Mol Biol. 2012;3(1):1-27</Citation>
<ArticleIdList>
<ArticleId IdType="pubmed">22509477</ArticleId>
</ArticleIdList>
</Reference>
<Reference>
<Citation>Cell. 2011 Mar 4;144(5):646-74</Citation>
<ArticleIdList>
<ArticleId IdType="pubmed">21376230</ArticleId>
</ArticleIdList>
</Reference>
<Reference>
<Citation>Proc Natl Acad Sci U S A. 2015 May 26;112(21):6539-44</Citation>
<ArticleIdList>
<ArticleId IdType="pubmed">25964345</ArticleId>
</ArticleIdList>
</Reference>
<Reference>
<Citation>Oncotarget. 2017 Feb 21;8(8):13344-13356</Citation>
<ArticleIdList>
<ArticleId IdType="pubmed">28076853</ArticleId>
</ArticleIdList>
</Reference>
<Reference>
<Citation>Mol Cell Biol. 2004 Feb;24(3):976-84</Citation>
<ArticleIdList>
<ArticleId IdType="pubmed">14729946</ArticleId>
</ArticleIdList>
</Reference>
<Reference>
<Citation>Cell Metab. 2015 Mar 3;21(3):392-402</Citation>
<ArticleIdList>
<ArticleId IdType="pubmed">25738455</ArticleId>
</ArticleIdList>
</Reference>
<Reference>
<Citation>J Cancer. 2016 Mar 26;7(6):711-21</Citation>
<ArticleIdList>
<ArticleId IdType="pubmed">27076853</ArticleId>
</ArticleIdList>
</Reference>
<Reference>
<Citation>Curr Oncol Rep. 2009 Mar;11(2):111-6</Citation>
<ArticleIdList>
<ArticleId IdType="pubmed">19216842</ArticleId>
</ArticleIdList>
</Reference>
<Reference>
<Citation>Mol Med Rep. 2014 Apr;9(4):1299-304</Citation>
<ArticleIdList>
<ArticleId IdType="pubmed">24535197</ArticleId>
</ArticleIdList>
</Reference>
<Reference>
<Citation>N Engl J Med. 1986 Sep 11;315(11):657-63</Citation>
<ArticleIdList>
<ArticleId IdType="pubmed">2943992</ArticleId>
</ArticleIdList>
</Reference>
<Reference>
<Citation>World J Gastroenterol. 2018 Nov 7;24(41):4679-4690</Citation>
<ArticleIdList>
<ArticleId IdType="pubmed">30416315</ArticleId>
</ArticleIdList>
</Reference>
<Reference>
<Citation>Cells. 2019 Jan 26;8(2):</Citation>
<ArticleIdList>
<ArticleId IdType="pubmed">30691108</ArticleId>
</ArticleIdList>
</Reference>
<Reference>
<Citation>Nat Rev Cancer. 2004 Oct;4(10):793-805</Citation>
<ArticleIdList>
<ArticleId IdType="pubmed">15510160</ArticleId>
</ArticleIdList>
</Reference>
<Reference>
<Citation>Mol Cancer Res. 2003 Dec;1(14):1001-8</Citation>
<ArticleIdList>
<ArticleId IdType="pubmed">14707283</ArticleId>
</ArticleIdList>
</Reference>
<Reference>
<Citation>Sci Rep. 2019 Feb 11;9(1):1729</Citation>
<ArticleIdList>
<ArticleId IdType="pubmed">30742053</ArticleId>
</ArticleIdList>
</Reference>
<Reference>
<Citation>Cell. 1992 Aug 21;70(4):523-6</Citation>
<ArticleIdList>
<ArticleId IdType="pubmed">1505019</ArticleId>
</ArticleIdList>
</Reference>
<Reference>
<Citation>Drug Resist Updat. 2018 May;38:1-11</Citation>
<ArticleIdList>
<ArticleId IdType="pubmed">29857814</ArticleId>
</ArticleIdList>
</Reference>
<Reference>
<Citation>J Surg Oncol. 2015 Mar 15;111(4):414-22</Citation>
<ArticleIdList>
<ArticleId IdType="pubmed">25488476</ArticleId>
</ArticleIdList>
</Reference>
<Reference>
<Citation>Med Sci Monit. 2019 Jul 31;25:5666-5673</Citation>
<ArticleIdList>
<ArticleId IdType="pubmed">31363077</ArticleId>
</ArticleIdList>
</Reference>
<Reference>
<Citation>Cell Stem Cell. 2015 May 7;16(5):547-55</Citation>
<ArticleIdList>
<ArticleId IdType="pubmed">25865501</ArticleId>
</ArticleIdList>
</Reference>
<Reference>
<Citation>Trends Mol Med. 2011 Jul;17(7):347-62</Citation>
<ArticleIdList>
<ArticleId IdType="pubmed">21481637</ArticleId>
</ArticleIdList>
</Reference>
<Reference>
<Citation>Cell. 1998 Oct 2;95(1):5-8</Citation>
<ArticleIdList>
<ArticleId IdType="pubmed">9778240</ArticleId>
</ArticleIdList>
</Reference>
<Reference>
<Citation>Oncotarget. 2016 Jan 12;7(2):1395-407</Citation>
<ArticleIdList>
<ArticleId IdType="pubmed">26593251</ArticleId>
</ArticleIdList>
</Reference>
<Reference>
<Citation>Genes Dev. 1999 Jan 15;13(2):152-7</Citation>
<ArticleIdList>
<ArticleId IdType="pubmed">9925639</ArticleId>
</ArticleIdList>
</Reference>
<Reference>
<Citation>Mol Genet Metab. 2012 Jul;106(3):385-94</Citation>
<ArticleIdList>
<ArticleId IdType="pubmed">22896851</ArticleId>
</ArticleIdList>
</Reference>
<Reference>
<Citation>Oncotarget. 2015 Nov 10;6(35):37398-409</Citation>
<ArticleIdList>
<ArticleId IdType="pubmed">26460957</ArticleId>
</ArticleIdList>
</Reference>
<Reference>
<Citation>Nature. 2013 Jun 6;498(7452):109-12</Citation>
<ArticleIdList>
<ArticleId IdType="pubmed">23685455</ArticleId>
</ArticleIdList>
</Reference>
<Reference>
<Citation>Nat Genet. 1998 Dec;20(4):398-400</Citation>
<ArticleIdList>
<ArticleId IdType="pubmed">9843217</ArticleId>
</ArticleIdList>
</Reference>
<Reference>
<Citation>EMBO J. 2004 Sep 15;23(18):3689-99</Citation>
<ArticleIdList>
<ArticleId IdType="pubmed">15343266</ArticleId>
</ArticleIdList>
</Reference>
<Reference>
<Citation>Haematologica. 2014 May;99(5):858-64</Citation>
<ArticleIdList>
<ArticleId IdType="pubmed">24334295</ArticleId>
</ArticleIdList>
</Reference>
<Reference>
<Citation>Cancer Biol Med. 2014 Mar;11(1):1-19</Citation>
<ArticleIdList>
<ArticleId IdType="pubmed">24738035</ArticleId>
</ArticleIdList>
</Reference>
<Reference>
<Citation>AAPS J. 2015 Jan;17(1):65-82</Citation>
<ArticleIdList>
<ArticleId IdType="pubmed">25236865</ArticleId>
</ArticleIdList>
</Reference>
<Reference>
<Citation>Tumour Biol. 2016 Jan;37(1):405-12</Citation>
<ArticleIdList>
<ArticleId IdType="pubmed">26219901</ArticleId>
</ArticleIdList>
</Reference>
<Reference>
<Citation>Nat Cell Biol. 2015 Apr;17(4):351-9</Citation>
<ArticleIdList>
<ArticleId IdType="pubmed">25774832</ArticleId>
</ArticleIdList>
</Reference>
<Reference>
<Citation>J Exp Clin Cancer Res. 2015 Dec 30;34:159</Citation>
<ArticleIdList>
<ArticleId IdType="pubmed">26714461</ArticleId>
</ArticleIdList>
</Reference>
<Reference>
<Citation>Oncogene. 1999 Dec 13;18(53):7637-43</Citation>
<ArticleIdList>
<ArticleId IdType="pubmed">10618703</ArticleId>
</ArticleIdList>
</Reference>
<Reference>
<Citation>Ann Oncol. 2018 Jan 1;29(1):264-270</Citation>
<ArticleIdList>
<ArticleId IdType="pubmed">29045536</ArticleId>
</ArticleIdList>
</Reference>
<Reference>
<Citation>Science. 1956 Aug 10;124(3215):269-70</Citation>
<ArticleIdList>
<ArticleId IdType="pubmed">13351639</ArticleId>
</ArticleIdList>
</Reference>
<Reference>
<Citation>Cell Metab. 2006 Mar;3(3):177-85</Citation>
<ArticleIdList>
<ArticleId IdType="pubmed">16517405</ArticleId>
</ArticleIdList>
</Reference>
<Reference>
<Citation>Clin Cancer Res. 2014 May 15;20(10):2595-606</Citation>
<ArticleIdList>
<ArticleId IdType="pubmed">24634381</ArticleId>
</ArticleIdList>
</Reference>
<Reference>
<Citation>EMBO J. 2006 Jun 7;25(11):2615-22</Citation>
<ArticleIdList>
<ArticleId IdType="pubmed">16757976</ArticleId>
</ArticleIdList>
</Reference>
<Reference>
<Citation>Cell Stem Cell. 2012 Nov 2;11(5):596-606</Citation>
<ArticleIdList>
<ArticleId IdType="pubmed">23122287</ArticleId>
</ArticleIdList>
</Reference>
<Reference>
<Citation>Cancer Biol Ther. 2014;15(11):1533-41</Citation>
<ArticleIdList>
<ArticleId IdType="pubmed">25482950</ArticleId>
</ArticleIdList>
</Reference>
<Reference>
<Citation>Cancer Lett. 2013 Jan 1;328(1):18-26</Citation>
<ArticleIdList>
<ArticleId IdType="pubmed">22922303</ArticleId>
</ArticleIdList>
</Reference>
<Reference>
<Citation>Ann N Y Acad Sci. 2016 Oct;1381(1):66-73</Citation>
<ArticleIdList>
<ArticleId IdType="pubmed">27399176</ArticleId>
</ArticleIdList>
</Reference>
<Reference>
<Citation>J Neurosci. 2011 Mar 30;31(13):4858-67</Citation>
<ArticleIdList>
<ArticleId IdType="pubmed">21451024</ArticleId>
</ArticleIdList>
</Reference>
<Reference>
<Citation>Science. 1956 Feb 24;123(3191):309-14</Citation>
<ArticleIdList>
<ArticleId IdType="pubmed">13298683</ArticleId>
</ArticleIdList>
</Reference>
</ReferenceList>
</PubmedData>
</PubmedArticle>

</PubmedArticleSet>

kaz2100 12-06-2020 04:13 AM

Hya

Quote:

Originally Posted by pan64 (Post 6191563)

Thank you for your post.

It looks like that this adv had been updated (in wxpython?) since original script was written as my previous post (dated 07-07-2020). And to make my life complicated, Debian packages are not quite updated. I need to straighten these knots.

So far, the suggested trick has not been worked, but one step ahead.

cheers

teckk 12-06-2020 06:00 AM

That way that you posted that destroys the line numbers, and therefor makes it impossible to parse with an xml parser.

I saved that as test.xml to look at it.
You can't have that xml file with all separate lines.

You should have posted that between code tags to preserve the format.

What was it that you were wanting from that again? I looked at what you posted,

When you save that xml file properly, the way it comes from the server, then this should parse these example items and spit them out.

testxml.py
Code:

#!/usr/bin/python

from xml.etree import ElementTree
from urllib import request

#Make a user agent string for urllib to use
agent = ('Mozilla/5.0 (Windows NT 10.1; Win64; x64; rv:78.0) '
        'Gecko/20100101 Firefox/78.0')
       
user_agent = {'User-Agent': agent}

class MakeList():
    def __init__(self, url, fname):
   
        #Get the xml to parse
        req = request.Request(url, data=None, headers=user_agent)
        html = request.urlopen(req)
        tree = ElementTree.parse(html)
        root = tree.getroot()
       
        #Get tag data
        tagA = root.findall('./PubmedArticleSet/item/Year')
        tagB = root.findall('./PubmedArticleSet/item/Volume')
        tagC = root.findall('./PubmedArticleSet/item/Title')
        tagD = []
       
        #Append lines with separator
        for a,b,c in zip(tagA,tagB,tagC):
            tagD.extend([a.text, b.text, c.text, '_' * 70])
           
        #Print
        for i in tagD:
            print(i)
               
        #Write list to file
        with open((fname), 'a') as f:
            for line in tagD:
                f.write('%s\n' % line)
               
if __name__ == "__main__":
   
    #Urls, log names
    A = ('http://...xml', 'Mylog.log')

    B = ('file:///local/file/test.xml', 'Mylog.log')
   
    #Choose xml source here
    url, fname = B

    MakeList(url, fname)

I think so, but without a valid url or valid xml file I can't be sure.

Edit: Fixed a line

kaz2100 12-07-2020 01:30 AM

Hya

teckk: Thank you for your reply and time. Apology for missing format, yes, I should have posted it with code tag. I currently try analyzing the code with your script. Probably, it will work, but not sure yet.

About wxpython version: While I was working on testing and stable Debian packages, situation accidentally (?) changed. With pycharm, core file chokes with exception at import. When run without IDE, some attribute error at same point.

It looks like a possible one step (either forward, sideways or backward)

cheers

kaz2100 12-08-2020 12:44 AM

Hya

self reply

Quote:

About wxpython version: While I was working on testing and stable Debian packages, situation accidentally (?) changed. With pycharm, core file chokes with exception at import. When run without IDE, some attribute error at same point.
I found that this error is
Code:

module 'wx' has no attribute 'wizard'
If I may go back to my post #1,
How to trace from python script to definition of <class 'AttributeError'>? Yes, this site has description, but something like C header file linked to script would be nicer. (Reason: No worry about python version!)

cheers

teckk 12-08-2020 07:11 AM

Read the python docs.
https://www.wxpython.org/
https://www.tutorialspoint.com/wxpython/index.htm
https://wiki.wxpython.org/wxPython
https://pythonhosted.org/wxPython/
https://github.com/wxWidgets/wxPython-Classic

Do you have a python script that is dated and doesn't work? That's normal for python. The python devs change python all the time. Backwards compatible and python are not synonyms.

You are going to have to learn python if you want to use python.
https://docs.python.org/3/
https://wiki.qt.io/Porting_from_QtWebKit_to_QtWebEngine
https://docs.python.org/3/library/tkinter.html
https://www.guru99.com/python-tutorials.html
https://www.programcreek.com/python/

Porting a python2 script to python3 may be a hard or impossible task. You'll have to do a rewrite, or use something else.

You can also get python help from the python shell.
Code:

python
Python 3.9.0 (default, Oct  7 2020, 23:09:01)
[GCC 10.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.

>>> from time import sleep
>>> help(sleep)
sleep(...)
    sleep(seconds)
   
    Delay execution for a given number of seconds.  The argument may be
    a floating point number for subsecond precision
    ...

I looked back through the thread. #29 posts, and you have yet not posted the python script that you are having problems with. Ok, you have had your hand held about enough now.

==========================================================================

Here is how your post should have looked.

Hey folks, I have a python script that does not work. Tell me what's wrong with this.
Code:

import time

for i in range(0, 10):
    print(i)
    sleep(1)

I get this error
Code:

0
Traceback (most recent call last):
  File "<stdin>", line 3, in <module>
NameError: name 'sleep' is not defined

I can't figure that out, can you. Answer: Yes I can.

kaz2100 12-09-2020 08:25 PM

Hya

Thank you for your post.

Yes, I totally agree with you (#30).

I have read only a small part of these documents. I need to read more.

Yes, I should have posted like your example. Reason I cannot is that I have difficulty in pointing out (a) guilty line(s).

***
So far, I have found that
1) with python2, wx has a module named wizard
2) with python3, wx does not

I need to figure out which particular statement requires wizard, .. If I knew, I could. Most probably, if I knew, I might be able to solve it.

I am lost in this step.

As posted in #28 briefly, with pycharm, "import wx" chokes by ValueError, and execution stops do not reach "AttributeError". There are many warning messages, but I cannot find any clue.
***

Your two scripts (#22, #30), are great gifts. I can follow program flow. With #30, I can locate sleep without your hint. (using either help(time) or inspecting /usr/lib/python3 tree)

I am getting used to python little by little.

cheers


All times are GMT -5. The time now is 03:04 PM.