Re: [Tutor] __weakref__ question

2019-07-25 Thread Mats Wichmann
On 7/24/19 1:57 PM, Sarah Hembree wrote:
> Can anyone provide some simple example/s or two or three of using weakref?
> I'm baffled and not seeing any documentation that is meaningful. My
> interest is to minimize memory usage (generally speaking, overall) and am
> wondering if this might help.

The answer is "maybe" and as a guess "probably not" going to give
signifgant memory savings - but it depends on circumstances.

It would help if you could describe a bit more of the scenario that
causes you to worry about memory usage.

I looked for documentation on __weakref__ since you said there didn't
seem to be anything meaningful and agree there's not much to go on - it
mostly seems to be something you have to fiddle with if you're using
__slots__.  On the other hand, the weakref module, which is what you're
more likely to directly use, seems reasonably well documented.

There are sure to be people with more expertise here who can explain
this better... but the two prominent uses of weakref seem to be in
caching, and in avoiding reference loops (or rather avoiding problems
related to them).  In the former case, if the things you put in your
cache are weak references, they can be garbage-collected by the Python
interpreter as needed, but before that happens you can refer to them.
Where it perhaps makes sense is where you have an object that is
expensive that you're doing some processing on, and you also add it,
with a weak reference to a list of recent objects.  Once you're done...
well, I find that what I'm saying here is actually said better by the
documentation so I'll stop, just read there:

https://docs.python.org/3/library/weakref.html

The latter case, reference cycles, where things refer to each other in a
way that potentially nothing gets released, ought to eventually get
caught by the interpreter which has a garbage collection algorithm for
this, but you can speed things along by being explicit. Something like
this perhaps:

import ctypes

# Use ctypes to access unreachable object by memory address.
class PyObject(ctypes.Structure):
_fields_ = [("refcnt", ctypes.c_long)]

d1 = {}
d2 = {}
d1['obj2'] = d2
d2['obj1'] = d1

daddr = id(d1)
print("d1 ref count:", PyObject.from_address(daddr).refcnt)
## output: d1 ref count: 2

del d1, d2
print("d1 ref count:", PyObject.from_address(daddr).refcnt)
## output: d1 ref count: 2

## There's a non-zero refcount even though both dictionaries
## have been removed: d2 couldn't go away completely because
## it was still being referenced in d2, and d2 couldn't go away
## completely because it was still being referenced in d1,
## which couldn't go away because...

## We can change this by marking the values as weak references:

n1 = weakref.WeakValueDictionary()
n2 = weakref.WeakValueDictionary()
n1['obj2'] = n2
n2['obj1'] = n1

naddr = id(n1)
print("n1 ref count:", PyObject.from_address(naddr).refcnt)
## output: n1 ref count: 1

del n1, n2
print("n1 ref count:", PyObject.from_address(naddr).refcnt)
## output: n1 ref count: 0
## :: weakrefs don't contribute to the refcount.


Does this help at all?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] REQUIRED SUPPORT FOR CODE

2019-07-25 Thread NITESH KUMAR
Dear Sir/Madam

I want to make Autocomplete searchbox using database .Please suggest me the
code for this.


Thanks & Regards
Nitesh Kumar
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] REQUIRED SUPPORT FOR CODE

2019-07-25 Thread Mats Wichmann
On 7/25/19 9:58 AM, NITESH KUMAR wrote:
> Dear Sir/Madam
> 
> I want to make Autocomplete searchbox using database .Please suggest me the
> code for this.

Your question leaves many more questions...

A searchbox implies you're using a graphical toolkit. Which one do you
intend to use (there are many available for Python)?  Or is your gui a
web browser maybe?

What do you mean "search... using database"?  Do you want the expanded
text to be used to search a database?  Or do you want to feed unexpanded
entered text to a database to get it to give you back completion
possibilities? Where would that data be coming from?  As you just trying
to replicate / replace Elasticsearch?

and so on  it's likely you can find some existing code for this on
the web if you search a bit.  It's a pretty specialized problem, don't
know if anyone here has any specific places to point you to.  Which
isn't really what this list is for anyway.

The normal model here is you try something and ask for help if you can't
get it to work. Something like this:

 -  Send a code example that illustrates your problem - If possible,
make this a minimal example rather than an entire application.
 -  Details on how you attempted to solve the problem on your own.
 -  Full version information — for example, "Python 3.6.4 with
discord.py 1.0.0a". Mention the operating system (Linux, Mac, Windows)
as well.
 -  The full traceback if your code raises an exception - Do not curate
the traceback as you may inadvertently exclude information crucial to
solving your issue.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Fw: CSC1010H 4th assignment

2019-07-25 Thread Mahima Daya
hi there, please could you assist.



From: York Singer 
Sent: Thursday, 25 July 2019 20:44
To: Mahima Daya 
Subject: CSC1010H 4th assignment


Disclaimer - University of Cape Town This email is subject to UCT policies and 
email disclaimer published on our website at 
http://www.uct.ac.za/main/email-disclaimer or obtainable from +27 21 650 9111. 
If this email is not related to the business of UCT, it is sent by the sender 
in an individual capacity. Please report security incidents or abuse via 
https://csirt.uct.ac.za/page/report-an-incident.php.

Disclaimer

The information contained in this communication from the sender is 
confidential. It is intended solely for use by the recipient and others 
authorized to receive it. If you are not the recipient, you are hereby notified 
that any disclosure, copying, distribution or taking action in relation of the 
contents of this information is strictly prohibited and may be unlawful.

This email has been scanned for viruses and malware, and may have been 
automatically archived by Mimecast Ltd, an innovator in Software as a Service 
(SaaS) for business. Providing a safer and more useful place for your human 
generated data. Specializing in; Security, archiving and compliance. To find 
out more visit the Mimecast website.
--- Begin Message ---



We removed a file from this message



Your organization's email policy doesn't permit this type of file. If you need 
it, please
contact your administrator.

–––
File Details

Filename: frogsandtoads.py
Size: 994 bytes

–––

Powered by Mimecast

© 2003 - 2019 Mimecast Services Limited.

--- End Message ---
--- Begin Message ---



We removed a file from this message



Your organization's email policy doesn't permit this type of file. If you need 
it, please
contact your administrator.

–––
File Details

Filename: tracking.py
Size: 1431 bytes

–––

Powered by Mimecast

© 2003 - 2019 Mimecast Services Limited.

--- End Message ---
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fw: CSC1010H 4th assignment

2019-07-25 Thread Steven D'Aprano
On Thu, Jul 25, 2019 at 07:04:52PM +, Mahima Daya wrote:

> hi there, please could you assist.

Yes, certainly. If you have questions about Python, you can ask 
concrete, specific questions. If you ask vague questions like "please 
help" expect to be ignored or told to do your own homework.

You should start by learning how to ask good questions about your code. 
Please read this:

http://sscce.org/

It is written mostly for Java programmers but it applies equally to any 
programming language, including Python.

And remember that asking people to work on your assignments without 
crediting them is almost certainly a violation of your university's 
standards of academic ethics.

-- 
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fw: CSC1010H 4th assignment

2019-07-25 Thread Alan Gauld via Tutor
On 25/07/2019 20:04, Mahima Daya wrote:
> hi there, please could you assist.

With what?
Your subject tells us absolutely nothing.
Your message gives us no clues.

The fact that you are posting to the Python tutor list suggests
you might have a question about Python programming. But what
that is we cannot even begin to speculate.

Please ask again with a concise description of your task,
what you have tried and the outcome.

Include any code, include the full text of any error messages.
Tell us the OS and programming language (including versions)
that you are using.

We will not do your homework for you. We expect to see your
effort and a specific question that we can answer.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] REQUIRED SUPPORT FOR CODE

2019-07-25 Thread Alan Gauld via Tutor
On 25/07/2019 16:58, NITESH KUMAR wrote:
> I want to make Autocomplete searchbox using database .Please suggest me the
> code for this.

Since you tell us next to noting we can only make wild suggestions.
Try to find a project that does the same thing - ideally one written
in Python (assuming that you are using python?) and see how it does it.

Failing that provide us with a lot more detail.
What kind of application is it? - Desktop? GUI? command line? Web based?
Mobile app?

What tools are you using - specifically any web or GUI toolkits.

What OS and python versions are you using?

What kind of database?

How do you anticipate this would work? Give us some examples?
#
-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fw: CSC1010H 4th assignment

2019-07-25 Thread David Rock

> On Jul 25, 2019, at 18:23, Alan Gauld via Tutor  wrote:
> 
> On 25/07/2019 20:04, Mahima Daya wrote:
>> hi there, please could you assist.
> 
> 
> Include any code, include the full text of any error messages.
> Tell us the OS and programming language (including versions)
> that you are using.
> 
> We will not do your homework for you. We expect to see your
> effort and a specific question that we can answer.


It also looks like you tried to attach some files that have code in them.   
Attachments won’t come through.  You will need to post any code in-line in the 
body of the email if we are going to be able to see it.


— 
David Rock
da...@graniteweb.com




___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] REQUIRED SUPPORT FOR CODE

2019-07-25 Thread john fabiani

Dabo has an AutoComplete method.  You review how it was done.

Johnf

On 7/25/2019 4:26 PM, Alan Gauld via Tutor wrote:

On 25/07/2019 16:58, NITESH KUMAR wrote:

I want to make Autocomplete searchbox using database .Please suggest me the
code for this.

Since you tell us next to noting we can only make wild suggestions.
Try to find a project that does the same thing - ideally one written
in Python (assuming that you are using python?) and see how it does it.

Failing that provide us with a lot more detail.
What kind of application is it? - Desktop? GUI? command line? Web based?
Mobile app?

What tools are you using - specifically any web or GUI toolkits.

What OS and python versions are you using?

What kind of database?

How do you anticipate this would work? Give us some examples?
#

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor